[Numpy-discussion] odd behavior for numpy.ndarray index?
Sun Sep 9 21:47:49 CDT 2007
On 9/9/07, Orest Kozyar <email@example.com> wrote:
> In the following output (see below), why would x[1,None] work, but
> x[1,None,2] or even x[1,2,None] not work?
None is the same thing as newaxis (newaxis is just an alias for None). Armed
with that tidbit, a little perusing of the docs should quickly explain the
behaviour you are seeing.
Incidentally, I would be very interested in a solution that allows me to
> index numpy arrays using a list/iterable that might contain None
> values. Is
> there a straightforward way to do so, or should I just use list
> comprehensions (i.e. [x[a] for a in indices if a])?
You could try something using compress x[compress(indices, indices)] for
example. Whether that's superior to a iterator solution would probably
depend on the problem. I'd probably use fromiter instead of a list
comprehension if I went that route though. There are probably other ways
too. It very much depends on the details and performance requirements of
what you are trying to do.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion