更新数组元素 [英] Update array elements

查看:87
本文介绍了更新数组元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好吗

我尝试更新数组的元素但是它没有正确执行

例如我有这个数组:



hello there
I try to update elements of a array but it does not perform correctly
for instance I have this array:

static double[,] weigh = { { 0.05, 0.1 }, { 0.2, 0.2 }, { 0.5, 0.5 } };





我尝试在其上执行此操作:







and I try to perform this on it:


for (k = 0; k < 2; k++)
                            {
                                if (z_input[k] > 0.0)
                                {
                                    bias[k] = bias[k] + 0.5 * (-1.0 - z_input[k]);
                                    weigh[k, 0] += (0.5 * (-1.0 - z_input[k]) * input1);
                                    weigh[k, 1] += (0.5 * (-1.0 - z_input[k]) * input2);
                                }
                            }







在w [0,0]上执行和w [0,1]正确但给我w [1,0]和w [1,1]错了!

它有什么问题?

帮助我< br $> b $ b谢谢



我尝试过:






it performs on w[0,0] and w[0,1] correctly but give me w[1,0] and w[1,1] wrong!
what's wrong with it?
help me
thanks

What I have tried:

static int[,] input = { { 1, 1 }, { 1, -1 }, { -1, 1 } };
        static int[] target = { -1, 1, 1 };
        static double[,] weigh = { { 0.05, 0.1 }, { 0.2, 0.2 } };
        static double[] vector = { 0.5, 0.5 };
        static double[] bias = { 0.3, 0.15, 0.5 };
        static bool epoch = true;
        static int input1 = 0, input2 = 0;
        static int k = 0;
        static double[] z_input = new double[2];
        static int[] z_layer = new int[2];
        static double y_input;
        static int y;







if (target[j] == -1)
                       {

                           for (k = 0; k < 2; k++)
                           {
                               if (z_input[k] > 0.0)
                               {
                                   bias[k] = bias[k] + 0.5 * (-1.0 - z_input[k]);
                                   weigh[k, 0] += (0.5 * (-1.0 - z_input[k]) * input1);
                                   weigh[k, 1] += (0.5 * (-1.0 - z_input[k]) * input2);
                               }
                           }

                       }

推荐答案

我们没有因为你没有给我们一个自主的代码片段,我们无法测试你的代码或重现问题,这可能是什么问题;

唯一有用的建议是学习调试器看看代码正在做什么。



有一个工具可以让你看到代码在做什么,它的名字是调试器。它也是一个很好的学习工具,因为它向你展示了现实,你可以看到哪种期望与现实相符。

当你不明白你的代码在做什么或为什么它做它做的时候,答案就是答案是调试器

使用调试器查看代码正在执行的操作。只需设置断点并查看代码执行情况,调试器允许您逐行执行第1行并在执行时检查变量。



调试器 - 维基百科,免费的百科全书 [ ^ ]



掌握Visual Studio 2010中的调试 - 初学者指南 [ ^ ]

使用Visual Studio 2010进行基本调试 - YouTube [ ^ ]

在Visual Studio中调试C#代码 - 您管 [ ^ ]

调试器在这里向您展示您的代码正在做什么,您的任务是与它应该做什么进行比较。

调试器中没有魔法,它找不到错误,它只是帮助你。当代码没有达到预期的效果时,你就接近了一个错误。

We have no idea of what can go wrong because you didn't gave us an autonomous piece of code, we can't test your code or reproduce the problem;
The only useful advice is to learn the debugger to see what the code is doing.

There is a tool that allow you to see what your code is doing, its name is debugger. It is also a great learning tool because it show you reality and you can see which expectation match reality.
When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]
Debugging C# Code in Visual Studio - YouTube[^]
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
引用:

with debugger我发现权重是错误的。

with debugger I found that the weights are wrong.



你能用一小段重现问题的代码更新问题吗?

权重错误id没有提供信息,请提供详细信息。


Can you update the question with a short piece of code that reproduce the problem ?
"weights are wrong" id not informative, give details.


这篇关于更新数组元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆