Stacking arrays...
Christopher Barker
Chris.Barker at noaa.gov
Tue Nov 7 13:56:56 EST 2006
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
More information about the NumPy-Discussion
mailing list