我正在尝试让AI学习and函数,但这个3d数组不起作用
int[, ,] inputs =
{
{ { 0, 0 }, {0} },
{ { 0, 1 }, { 0 } },
{ { 1, 0 }, { 0 } },
{ { 1, 1 }, { 1 } }
};发布于 2016-04-17 02:41:43
您已经声明了一个矩形数组-尽管我认为"cuboid“数组在这种情况下更合适。但是你必须让每个“子数组”初始化器具有相同的长度。为了继续几何比喻,每一列的长度都必须相同-但有些列的长度是2,有些列的长度是1。
因此这将进行编译,例如:
int[, ,] inputs =
{
{ { 0, 0 }, { 0, 0 } },
{ { 0, 1 }, { 0, 0 } },
{ { 1, 0 }, { 0, 0 } },
{ { 1, 1 }, { 1, 0 } }
};这现在是一个4x2x2的数组。
如果你想让每个“最后的子数组”都有不同的长度,你可以有一个一维数组的矩形数组:
int[,][] inputs =
{
{ new[] { 0, 0 }, new[] { 0 } },
{ new[] { 0, 1 }, new[] { 0 } },
{ new[] { 1, 0 }, new[] { 0 } },
{ new[] { 1, 1 }, new[] { 1 } }
};发布于 2016-04-17 02:39:10
int[, ,] inputs = new int[sizeX, sizeY, sizeZ];
for(int x = 0; x < inputs.GetLength(0); x++)
{
for(int y = 0; y < inputs.GetLength(1); y++)
{
for(int z = 0; z < inputs.GetLength(2); z++)
{
int element = inputs[x, y, z];
}
}
}https://stackoverflow.com/questions/36668096
复制相似问题