[SciPy-dev] [Numpy-discussion] Re: How to handle a[...] in numpy?
Sasha
ndarray at mac.com
Mon Jan 9 19:23:03 CST 2006
Attached patch implements indexing of zero rank arrays:
>>> x = array(42)
>>> x[...]
42
>>> x[()]
42
>>> x[()].dtype
<type 'int32_arrtype'>
>>> type(x[()])
<type 'int32_arrtype'>
Ellipsis and empty tuple are the only two valid indices.
So far there was only one +1 vote for the feature (from Francesc
Altet, who also suggested that x[()] be allowed). Does anyone object
to this feature?
I have also proposed to support x[...,newaxis] (see comment by
sdementen at http://www.scipy.org/wikis/numdesign/). I will add this
feature if there is interest.
Finally, if we make x[...] valid for rank-0 arrays, should x[...] =
value be allowed as well? I think it should, applying the principle of
least surprized. An additional consideration is that rank-0 arrays
are unhashable, but there is no obvious way to change their values.
The following example show that rank-0 arrays are in fact mutable (in
a non-obvious way):
>>> x = array(1)
>>> x.shape=(1,); x[0] = 42; x.shape=()
>>> x
Please comment on the following proposals:
1. x[...]
2. x[...] = value
3. x[..., newaxis]
-- sasha
More information about the Numpy-discussion
mailing list