May 30, 2009 taking a crosssection of a 3-D array | ||||
---|---|---|---|---|
| ||||
So, how do I take a cross section of a 3-D array. Basically I want to be able to take a 2D matrix from a 3-D array. auto m = a[][n][]; something like that. Any ideas? if you need more info, let me know. -Andrew |
May 30, 2009 Re: taking a crosssection of a 3-D array | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrew | Andrew:
> So, how do I take a cross section of a 3-D array. Basically I want to be able to take a 2D matrix from a 3-D array. auto m = a[][n][];
Languages (or libraries) like matlab and NumPy allow to slice nD arrays like you say, using a very compact syntax, but currently the D1/D2 languages aren't designed for people that perform "serious" numerical computations, so it doesn't offer built-in ways to slice nD arrays.
So you can write a function template that performs such slices, that insides copies items.
Currently D1/D2 1D arrays are 2-structs that point to a memory zone, so 2D arrays are 2-structs that contain a pointer to a memory zone of structs that contain pointers to memory zones of the "rows" of data.
Bye,
bearophile
|
Copyright © 1999-2021 by the D Language Foundation