Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java ArrayIndexOutOfBoundsException在3D数组中_Java_Arrays_Multidimensional Array_Neural Network - Fatal编程技术网

Java ArrayIndexOutOfBoundsException在3D数组中

Java ArrayIndexOutOfBoundsException在3D数组中,java,arrays,multidimensional-array,neural-network,Java,Arrays,Multidimensional Array,Neural Network,我试图为神经网络制作一个锯齿阵列,这给了我一个越界误差 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++) n

我试图为神经网络制作一个锯齿阵列,这给了我一个越界误差

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]];
int[]大小={
第一层,第二层,第三层
};
int k=尺寸。长度-1;
double[][]净=新的double[k][]];
int i;
对于(i=0;i
net[x][[y]
中y的大小应等于
net[x+1][y][]
的大小

我是在纸上写的,我想这会管用的

int[] sizes = {
    layer1, layer2, layer3
};
int k = sizes.length - 1;
所以,
k
等于2

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]];
                          ^^^^^^^^^^^^
                          ArrayIndexOutOfBoundsException

Boom,
sizes[i+1]
抛出
ArrayIndexOutOfBoundsException
,因为
sizes
只有索引0、1和2,您指的是
sizes[3]

您试过调试程序吗?哪一行失败了,错误到底是什么?(请格式化您的代码使其更可读…)顺便问一下,您真的没有大括号吗?如果是这样的话,那就是问题所在。@NateCook3不确定你想要实现什么,因为我不知道什么是
layer1
layer2
layer3
等等。查看我的答案,了解您获得
阵列索引OutOfBoundsException
@JarrodRoberson的原因。我不确定这与您标记的是什么样的重复。如果您已经有了答案,请不要对问题进行剧烈更改。