Stacking arrays...

Bill Baxter wbaxter at gmail.com
Tue Nov 7 18:41:37 EST 2006


dstack maybe? or does that add a dim on the other end?
--bb

On 11/8/06, Christopher Barker <Chris.Barker at noaa.gov> 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_ ?
>
> -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
>
> Chris.Barker at noaa.gov
>
> -------------------------------------------------------------------------
> 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 at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20061108/98a80663/attachment-0001.html>
-------------- next part --------------
-------------------------------------------------------------------------
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
-------------- next part --------------
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion


More information about the NumPy-Discussion mailing list