【发布时间】:2013-05-06 20:08:00
【问题描述】:
Layers 是 Node 的锯齿状数组,每个节点作为 source[] 和 destination[] 代表 Theta 的数组。
问题是,为什么当我更改第四行的代码时,链接这些对象后第五行仍然打印“0”?
theta t = new theta();
layers[1][i].source[j] = t;
layers[0][j].destination[i] = t;
layers[0][j].destination[i].weight = 5;
Console.WriteLine(layers[1][i].source[j].weight);
struct theta
{
public double weight;
public theta(double _weight) { weight = _weight; }
}
class node
{
public theta[] source;
public theta[] destination;
public double activation;
public double delta;
public node() { }
public node(double x) { activation = x; }
}
图层填充示例:
node n = new node();
n.destination = new theta[numberOfNodesPerHiddenLayer+1];
n.source = new theta[numberOfNodesPerHiddenLayer+1];
layers[i][j] = n;
【问题讨论】:
-
你应该澄清
layers数组是如何填充的。 -
请发布整个外部/嵌套循环(如果适用)代码 sn-p 因为不清楚索引 i 和 j 的来源。 Rgds,
-
将结构更改为类,一切都会正常工作。就目前的用途而言,在那里有结构是没有意义的
-
层在其每个维度上单独实例化。这是关于如何填充层(节点数组)的代码示例:
node n = new node();n.destination = new theta[numberOfNodesPerHiddenLayer+1];n.source = new theta[numberOfNodesPerHiddenLayer+1];layers[i][j] = n;
标签: c# class jagged-arrays