For easily finding values in a huge Array I want to use the "find"-Command of a List. The problem is, right now it is not a List, it is a 3D-Array.
This means, i need to convert my double[,,]-array to a
List<List<List<double>>> blabla
Example of an Array:
double[,,] myArray = new double[2,3,3];
Could look then like the following:
myArray[1,:,:] = 1.11 1.12 1.13
1.21 1.22 1.23
1.31 1.32 1.33
myArray[2,:,:] = 2.11 2.12 2.13
2.21 2.22 2.23
2.31 2.32 2.33
Can this be done by a one-liner using somehow the "Cast" command?
Thanks
Given your double[,,] myArray
you can do this:
var blabla =
myArray
.Cast<double>()
.Select((v, n) => new
{
x = n / (myArray.GetLength(2) * myArray.GetLength(1)),
y = (n / myArray.GetLength(2)) % myArray.GetLength(1),
value = v,
})
.GroupBy(q => q.x)
.Select(q =>
q
.GroupBy(
w => w.y,
w => w.value)
.Select(e => e.ToList())
.ToList())
.ToList();
That gives you the List<List<List<Double>>>
that you're looking for.
And all in a one-liner!
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments