[SciPy-user] Create n-dim array from axis

josef.pktd@gmai... josef.pktd@gmai...
Mon Mar 23 09:20:16 CDT 2009


On Mon, Mar 23, 2009 at 10:07 AM, Paul Hilscher
<p.hilscher@lsw.uni-heidelberg.de> 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,
>
> Paul

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.

For 2d you can convert the meshgrid directly to an ndarray

>>> np.array(np.meshgrid(x,y)).shape
(2, 3, 3)


Josef


More information about the SciPy-user mailing list