[Numpy-discussion] PEP updated

Sebastien.deMentendeHorne at electrabel.com Sebastien.deMentendeHorne at electrabel.com
Wed Feb 23 03:18:02 EST 2005


> For sequence behaviour len, indexing and iteration should work
> consistently, i.e., "a[i] for i in xrange(len(a))" and "x for x in a"
> should identically generate the contents of a.  Currently indexing and
> iteration occur along the first dimension, which for rank 0 arrays
> does not exist.  I understand that there is no burning desire to
> completely switch to Matlab-style one-dimensional indexing.  The
> alternatives are then giving rank 0 arrays exceptional semantics
> inconsistent with other arrays or raising an exception if len or
> iteration is applied to a rank 0 array.  Without exceptional semantics
> the only index expression that makes sense is a[()].  I would favor
> consistency here and raise an exception but there is one matter that
> raises some doubt: do programs expect that if __len__ and __iter__
> exist they will not fail?
> 

Looking at the code I wrote that must deal with special scalar vs array
cases, I noticed that an important feature that the rank-0/scalar should
have is a correct indexing behaviour with:
 a[..., NewAxis] or a[NewAxis] or a[NewAxis, ...]

By the way, isn't it easier to find a solution to this problem by looking at
specific pieces of code that currently needs an ugly case for scalar ?
Moreover, should this rank-0 array behaviour of scalar be extended to other
"scalar" objects ? Should we be able to use:
 p = (3,4)
 a = p[NewAxis]
 a.shape = (1,)
 a.typecode() ==> 'O'
?




More information about the NumPy-Discussion mailing list