# [SciPy-user] 3 dimensional arrays

Matthieu Brucher matthieu.brucher@gmail....
Thu Aug 23 09:36:16 CDT 2007

```Hi,

Don't forget that Python begins array indexing by 1.
Once this is known, b[:,:,1] gets the second element in your display, which
is coherent.

Matthieu

2007/8/23, Perez Kawumi <pepe_kawumi@yahoo.co.uk>:
>
> Hi ,
> I'm trying to create arrays in three-d. And then break them down into
> planes(e.g. h(:,:,1) below). I have attached a piece of matlab code and
> how it runs. I have also attached what I have done in python but having
> problems verifying if it's doing exactly what I want. Just wondering if
> anyone can help me do this in python. I
> Thanks Perez
>
> *Matlab code
> *>> b= rand(3,3,2)*10
> b(:,:,1) =
>     5.3960    6.7735    3.1040
>     6.2339    8.7683    7.7908
>     6.8589    0.1289    3.0730
>
> b(:,:,2) =
>     9.2668    0.7067    5.1625
>     6.7872    0.1193    4.5820
>     0.7432    2.2715    7.0320
>
> *Python code*
> >>> b = random.random((3,3,2))*10
> >>> b
> array([[[ 2.90701573,  5.43543163],
>         [ 3.23435142,  6.3642547 ],
>         [ 4.63504825,  4.4083266 ]],
>        [[ 6.21107005,  8.40185679],
>         [ 1.25017666,  6.25796949],
>         [ 8.69343579,  0.48324745]],
>        [[ 3.19007467,  2.65135416],
>         [ 5.8586314 ,  6.72327567],
>         [ 8.14780457,  2.39946201]]])
> >>> m = b[:,:,1]
> >>> m
> array([[ 5.43543163,  6.3642547 ,  4.4083266 ],
>        [ 8.40185679,  6.25796949,  0.48324745],
>        [ 2.65135416,  6.72327567,  2.39946201]])
>
> ------------------------------
> To help you stay safe and secure online, we've developed the all new *Yahoo!
> Security Centre*<http://us.rd.yahoo.com/mail/uk/taglines/default/security_centre/*http://uk.security.yahoo.com/>
> .
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-user/attachments/20070823/c6b2818a/attachment.html
```