简体   繁体   English

c#将三维数组转化为3个一维数组

[英]c# Tridimensional array into 3 single dimension arrays

Maybe it's a basic question, but I am not reaching the correct method to get the value of a tridimensional array item or get three separate single arrays from a tridimensional array.也许这是一个基本问题,但我没有找到正确的方法来获取三维数组项的值或从三维数组中获取三个单独的单个数组。

For a given float[,,] array3d as : {[a0,b0,c0], [a1,b1,c1], [a2,b2,c2]...} I need to get three arrays as: a{a0 , a1, a2}, b{b1, b2, b3} and c{c1, c2, c3}对于给定的float[,,] array3d为:{[a0,b0,c0], [a1,b1,c1], [a2,b2,c2]...} 我需要得到三个数组:a{a0 , a1, a2}, b{b1, b2, b3} 和 c{c1, c2, c3}

If it's not a direct method, I am trying to access to each element as array3d[row, column], but it's not working...如果它不是直接方法,我试图以 array3d[row, column] 的形式访问每个元素,但它不起作用......

            a = new float[length];
            b = new float[length];
            c = new float[length];

            for (int i = 0; i < length; i++)
            {
                a[i] = array3d[i, 0]; //how can I access to that row, column element?
                b[i] = array3d[i, 1];
                c[i] = array3d[i, 2];
            }

For 3D you have to provide 3 indexes to access a particular element.对于 3D,您必须提供 3 个索引来访问特定元素。 If i understand your question the following code should work for you如果我理解你的问题,下面的代码应该适合你

int[, ,] array3d = new int[2, 2, 3]{
            { { 1, 2, 3}, {4, 5, 6} },
            { { 7, 8, 9}, {10, 11, 12} }
        };
List<float> a = new List<float>;
List<float> b = new List<float>;
List<float> c = new List<float>;

for (int i = 0; i < 2; i++)
{

    for (int j = 0; j < 2; j++)
    {
        a.Add(array3d[i, j, 0]);
        b.Add(array3d[i, j, 1]);
        c.Add(array3d[i, j, 2]);
    }
}
     

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM