[Numpy-discussion] concatenating 1-D arrays to 2D
Fri Mar 23 13:57:09 CDT 2007
On 3/24/07, Sebastian Haase <firstname.lastname@example.org> wrote:
> > Then of course, there's r_ and c_:
> > c = numpy.c_[a,b]
> > c = numpy.r_[a[None],b[None]].T
> > --bb
> None is the same as newaxis - right?
Yes, newaxis is None. None is newaxis. Same thing. I just don't see
much advantage in spelling it numpy.newaxis, since it's pretty common
and not likely to ever change.
> But what is a[None] vs. a[:,N.newaxis] ?
a[None] is the same as a[None,:]. It prepends the new axis, so a
shape of (5,) becomes (1,5), a "row vector"
a[:,None] puts the new axis after the first axis, so shape of (5,)
becomes (5,1) a "column vector"
a[None,:,None] puts a new axis both before and after, so (5,) becomes (1,5,1).
If 'a' is higher dimensional, the same kind of thing goes. Wherever
None/newaxis appears in the index, insert a new axis there in the
Say A is shape (2,3,4), then
A[:,None,:,None] is shape (2,1,3,1,4). (Same as A[:,None,:,None,:]
since unspecified trailing indices are always taken to be ':')
More information about the Numpy-discussion