On 11/7/06, Christopher Barker <[EMAIL PROTECTED]> wrote:
> HI all,
>
> I'm trying to get the hang of this new r_ and c_ stuff.
>
> I need to take two MxN arrays, and stack them together into one MxNx2
> arrays. I found this works:
>
>  >>> a = N.ones((3,4))
>  >>> b = N.ones((3,4)) * 2
>  >>> a
> array([[ 1.,  1.,  1.,  1.],
>         [ 1.,  1.,  1.,  1.],
>         [ 1.,  1.,  1.,  1.]])
>  >>> b
> array([[ 2.,  2.,  2.,  2.],
>         [ 2.,  2.,  2.,  2.],
>         [ 2.,  2.,  2.,  2.]])
>  >>> a.shape = (3,4,1)
>  >>> b.shape = (3,4,1)
>  >>> c = N.c_[a,b]
>  >>> c.shape
> (3, 4, 2)
>  >>> c[0,0]
> array([ 1.,  2.])
>
>
> What I'm wondering is if there is a way to do that without explicitly
> adding the extra dimension to a and b before calling c_ ?
>

c=N.dstack([a,b]) seems to do the trick.

pau



> -Chris
>
>
> --
> Christopher Barker, Ph.D.
> Oceanographer
>
> NOAA/OR&R/HAZMAT         (206) 526-6959   voice
> 7600 Sand Point Way NE   (206) 526-6329   fax
> Seattle, WA  98115       (206) 526-6317   main reception
>
> [EMAIL PROTECTED]
>
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
>

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion

Reply via email to