[Numpy-discussion] Response to PEP suggestions

Robert Kern rkern at ucsd.edu
Fri Feb 18 11:14:21 CST 2005


Timo Korvola wrote:
> Robert Kern <rkern at ucsd.edu> writes:
> 
>>I'm not averse to len(x) returning 0 when given a rank-0 array. I see
>>it as giving up one consistency (that scalar-like objects don't have
>>lengths) for another (arrays having a common set of operations that
>>one can expect regardless of rank or shape).
> 
> 
> That would be akin to making 0/0 return 0.  It is possible to create
> arrays of length zero, e.g, by indexing with an empty slice, and these
> should not be confused with rank zero arrays.

Fair enough. I'm not averse to len(x) raising an exception when x is a 
rank-0 array either.  :-)

>>Might our PEP efforts be better spent locating and fixing the places
>>in core Python where rank-0 arrays won't be accepted as core ints and
>>floats?
> 
> 
> Sounds useful.
> 
> 
>>List/tuple indexing is one.
> 
> 
> Rank 0 arrays should also be kept in mind when defining array indexing
> in the PEP.

Hopefully, this would drop out cleanly from the regular array-indexing 
and not require too much in the way of special-casing.

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter




More information about the Numpy-discussion mailing list