[SciPy-user] Generating a 4D array from a set of 3D arrays
Wed May 21 13:42:30 CDT 2008
Thanks. I'm finding that scipy/numpy are very powerful (much more than matlab) but arrays/lists/tuples etc takes some getting used to.
>>> "Anne Archibald" <email@example.com> 5/21/2008 1:36 PM >>>
2008/5/21 Dharhas Pothina <Dharhas.Pothina@twdb.state.tx.us>:
> Thanks Anne, I don't know the final size so appending to a list is probably best. The array(big_list) seems to be working but for my future reference, what does the following do?
Well, concatenate concatenates arrays along an already-existing axis,
so the arrays need to be four-dimensional when I concatenate them. So
I turn my three-dimensional arrays, of shape (a,b,c), into
four-dimensional arrays of shape (1,a,b,c); I later concatenate along
axis 0. The way to add this new length-1 axis is by using np.newaxis.
For example, to turn an array A of shape (2,3) into an array of shape
A = A[:,np.newaxis,:]
The "..." just means "as many : as needed"; very useful when writing
generic functions, but here I was just too lazy to write
SciPy-user mailing list
More information about the SciPy-user