[英]ArrayIndexOutOfBoundsException in 3D array
I'm trying to make a jagged array for a neural network and this is giving me an out of bounds error... 我正在尝试为神经网络制作一个锯齿状的数组,这给了我一个超出范围的错误...
int[] sizes = {
layer1, layer2, layer3
};
int k = sizes.length - 1;
double[][][] net = new double[k][][];
int i;
for (i = 0; i < k; i++)
net[i] = new double[sizes[i]][];
for (int j = 0; j < sizes[i]; j++)
net[i][j] = new double[sizes[i + 1]];
The size of y in net[x][ ][y]
should be equal to the size of net[x+1][y][ ]
. net[x][ ][y]
的大小应等于net[x+1][y][ ]
。
I did it on paper and I thought that this would work. 我是在纸上做的,我认为这会起作用。
int[] sizes = {
layer1, layer2, layer3
};
int k = sizes.length - 1;
So, k
is equal to 2. 因此,
k
等于2。
int i;
for (i = 0; i < k; i++)
net[i] = new double[sizes[i]][];
After that loop i
is equal to 2. 在那个循环之后,
i
等于2。
for (int j = 0; j < sizes[i]; j++)
net[i][j] = new double[sizes[i + 1]];
^^^^^^^^^^^^
ArrayIndexOutOfBoundsException
Boom, sizes[i + 1]
throws ArrayIndexOutOfBoundsException
, since sizes
has only indices 0, 1 and 2 and you are referring to sizes[3]
. 吊杆,
sizes[i + 1]
抛出ArrayIndexOutOfBoundsException
,由于sizes
仅具有索引0,1和2以及你指的是sizes[3]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.