[Numpy-discussion] Response to PEP suggestions

Paul Barrett barrett at stsci.edu
Fri Feb 18 07:14:13 CST 2005


Timo Korvola wrote:

[snip, snip]

>>3)  Always returning rank-0 arrays.
>>
>>This may be a bit controversial as it is a bit of a change.
>>    
>>
>
>Indeed.  So you really do intend that if foo=array([1,2]), foo[0]
>should evaluate to array(1) rather than 1?
>
>  
>
>>But, my experience is that quite a bit of extra code is written to
>>check whether or not a calculation returns a Python-scalar
>>    
>>
>
>I suppose this may be necessary for code which operates on arrays of
>somewhat arbitrary rank and would not know without looking whether,
>e.g., foo[0] is a scalar or an array of positive rank.
>
>  
>
>>In particular len(a) does not work if a is a scalar,
>>    
>>
>
>Depends on what kinds of scalars are supported.  What about object
>arrays?
>
>  
>
>>but len(b) works if b is a rank-0 array
>>
How about proposing a PEP to extend Python's scalar behavior, so the 
len(a) works for either scalars or arrays.  Though I haven't thought 
this through in great detail, it would appear to be a transparent 
addition for most Python users who would never use this.  At the same 
time, we should also consider other behavior that would unify (or smear) 
the behavior of Python scalars and arrays.

 -- Paul

-- 
Paul Barrett, PhD      Space Telescope Science Institute
Phone: 410-338-4475    ESS/Science Software Branch
FAX:   410-338-4767    Baltimore, MD 21218





More information about the Numpy-discussion mailing list