[SciPy-user] Create n-dim array from axis
Tue Mar 24 06:43:38 CDT 2009
> On Mon, Mar 23, 2009 at 10:07 AM, Paul Hilscher
> <firstname.lastname@example.org> wrote:
>>> try mx, my = numpy.meshgrid(x, y)
>>> [zip(a,b) for (a,b) in zip(mx, my)]HTH,
>> Thanks a lot David, this works perfectly fine for 2-dimensions.
>> Is there any possibility to extend it to 3-dimensions with axis z, or
>> even to 4-dimensions giving axis w ?
>> Thanks again,
> I would also like to know what an efficient way is to do this. For
> arbitrary dimension, I never found anything except for a brute force
> loop or recursive function.
Would this do? Should work with arbitrary number of dimensions.
# startStopStep is a tuple/list of (start,stop,step) entities to
# define the axes
slices = [slice(start, stop, complex(0, step)) for
(start,stop,step) in startStopStep]
g = numpy.mgrid[slices].transpose()
print create_array(((0,1,3), (2,3,3)))
[[[ 0. 2. ]
[ 0.5 2. ]
[ 1. 2. ]]
[[ 0. 2.5]
[ 0.5 2.5]
[ 1. 2.5]]
[[ 0. 3. ]
[ 0.5 3. ]
[ 1. 3. ]]]
More information about the SciPy-user