question on use of newaxis

Hello List, I have a simple array a = array([1,2,3]) I want to take the last two terms and make it a column vector: a[[1,2],newaxis] But I get a funny error: TypeError: long() argument must be a string or a number, not 'NoneType' It does work if I do a[[1,2]][:,newaxis] But I don't understand why the first wouldn't work. Is there a reason such syntax is not supported? It would be very useful. Thanks, Mark

2011/2/9 Mark Bakker <markbak@gmail.com>:
a = array([1,2,3])
I want to take the last two terms and make it a column vector:
a[[1,2],newaxis] a[[1,2]][:,newaxis]
The former is advanced indexing, while the latter is basic slicing (after advanced indexing). See http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html. There, in the advanced indexing case, "All sequences and scalars in the selection tuple are converted to intp indexing arrays", and:
numpy.intp <type 'numpy.int32'>
. Thus it tries to interpret the None:
numpy.newaxis print repr(numpy.newaxis) None
as an ``numpy.intp``, hence the error. Since advanced indexing deletes axes of an ndarray and inserts new ones (see http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#integer, last point), a ``numpy.newaxis`` might be ambiguous. In your case, it would be not, though. Friedrich
participants (2)
-
Friedrich Romstedt
-
Mark Bakker