[Numpy-discussion] Re: [SciPy-dev] How to handle a[...] in numpy?

Francesc Altet faltet at carabos.com
Mon Jan 9 03:55:02 EST 2006


A Diumenge 08 Gener 2006 05:10, Sasha va escriure:
> In Numeric a[...] would return an array unless a was 0-rank and a
> python type othewise. What is the right way to do the same in numpy?
[snip]

> Proposal: Although I like a lot that 0-rank arrays and numpy scalar
> types non-iterable, it may be reasonable to allow a[...].  This way
> ellipsis can be interpereted as any number of  ":"s including zero.
> Another subscript operation that makes sense for scalars would be
> a[...,newaxis] or even a[{newaxis, }* ..., {newaxis,}*], where
> {newaxis,}* stands for any number of comma-separated newaxis tokens.
> This will allow one to use ellipsis in generic code that would work on
> any numpy type.  I will contribute code if there is any interest.

+1

More specifically, provided that:

In [65]: type(numpy.array([0])[...])
Out[65]: <type 'numpy.ndarray'>

In [66]: type(numpy.array([0])[0])
Out[66]: <type 'int32_arrtype'>

In [67]: type(numpy.array([0]).item())
Out[67]: <type 'int'>

I'd propose the next behaviour for 0-rank arrays:

In [65]: type(numpy.array(0)[...])
Out[65]: <type 'numpy.ndarray'>

In [66]: type(numpy.array(0)[()])   # Indexing a la numarray
Out[66]: <type 'int32_arrtype'>

In [67]: type(numpy.array(0).item())  # already works
Out[67]: <type 'int'>

-- 
>0,0<   Francesc Altet     http://www.carabos.com/
V   V   Cárabos Coop. V.   Enjoy Data
 "-"





More information about the NumPy-Discussion mailing list