|
From: Sasha <nd...@ma...> - 2006-01-10 03:22:12
|
Attached patch implements indexing of zero rank arrays: >>> x =3D 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[...] =3D 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 =3D array(1) >>> x.shape=3D(1,); x[0] =3D 42; x.shape=3D() >>> x Please comment on the following proposals: 1. x[...] 2. x[...] =3D value 3. x[..., newaxis] -- sasha |