[英]How to make a 2D array of 2D arrays
I tried to find a solution for this through many sources. 我试图通过许多渠道找到解决方案。 But in vain.
但是徒劳。 I have 3 2D array objects:
我有3个2D数组对象:
double[][] W1 = new double[5][10];
double[][] W2 = new double[2][3];
double[][] W3 = new double[4][6];
and I want another array object to contain those 3 array objects. 我希望另一个数组对象包含这3个数组对象。 How do I do it?
我该怎么做?
I found that it is possible to make many 1D arrays to an array of 2D arrays using the following 我发现可以使用以下方法将许多1D数组制作为2D数组的数组
double[][] W = new double[][]{W1, W2, W3}; //provided W1, W2, W3 are 1D arrays.
But how do I do the same for 2D arrays? 但是,如何对2D阵列执行相同操作?
A 1D array is declared as double[]
, ie []
of double
. 一维数组被声明为
double[]
即[]
的double
。
A 1D array of 1D arrays (a 2D array) is declared as double[][]
, ie []
of double[]
. 1D阵列(2D阵列)的一维阵列被声明为
double[][]
即[]
的double[]
A 1D array of 2D arrays (a 3D array) is declared as double[][][]
, ie []
of double[][]
. 2D阵列(一个3D阵列)的一维阵列被声明为
double[][][]
即[]
的double[][]
A 1D array of 3D arrays (a 4D array) is declared as double[][][][]
, ie []
of double[][][]
. 三维阵列(四维阵列中)的一维阵列被声明为
double[][][][]
即[]
的double[][][]
There is no practical distinction between a 3D array, a 1D array of 2D arrays and a 2D array of 1D arrays; 3D阵列,2D阵列的1D阵列和1D阵列的2D阵列之间没有实际区别。 or between a 4D array, a 1D array of 3D arrays and a 2D array of 2D arrays.
或在4D阵列,3D阵列的1D阵列和2D阵列的2D阵列之间。 It's purely how you choose to think about them.
纯粹是您选择考虑它们的方式。
I really can't think why you'd want to use arrays nested this deeply; 我真的不知道为什么您要使用嵌套此深度的数组。 I'd suggest you think about whether a better alternative might be exist.
我建议您考虑是否可能存在更好的选择。
So you want to initialize a 3D array from 3 2D arrays. 因此,您想从3个2D数组初始化一个3D数组。 That should do it
那应该做
double[][][] W = {W1, W2, W3};
Note how you don't need new
. 注意如何不需要
new
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.