-1

I have an array of values in a 3-D array, stored as [x,y,z]. A 3-D array is useful for the previous function, but in the current function, I would like z series' of [x,y] arrays. Is this possible? The array I have is input[x,y,z], and I would like it to be redone into 2-D arrays. x and y are the values for the 2-D array.

var dict = new Dictionary<int, double[,]>();
for (int files = 0; files < input.GetLength(2); files++)
{
    dict[files] = input[x,y,files]
}
Ogoun
  • 61
  • 2
  • 7

1 Answers1

4
var dict = new Dictionary<int, double[,]>();
for (int files = 0; files < input.GetLength(2); files++)
{
    double[,] twoD = new double[input.GetLength(0), input.GetLength(1)];
    for (int x = 0; x < input.GetLength(0); x++)
        for (int y = 0; y < input.GetLength(1); y++)
            twoD[x, y] = input[x, y, files];
    dict.Add(files, twoD);
}

This SO question might help as well.

Note that this does assume that your z values are unique.

Community
  • 1
  • 1
Jashaszun
  • 9,207
  • 3
  • 29
  • 57