|
From: Francesc A. <fa...@ca...> - 2006-01-09 11:54:20
|
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'>
=2D-=20
>0,0< Francesc Altet =A0 =A0 http://www.carabos.com/
V V C=E1rabos Coop. V. =A0=A0Enjoy Data
"-"
|