[Numpy-discussion] a==b for numpy arrays

David Goldsmith David.L.Goldsmith at noaa.gov
Mon Dec 11 20:19:17 EST 2006


Abel Daniel wrote:
> to what 'a+b' means with a and b being numpy arrays. But 'A=B' means something
> completely different than 'a==b'.
>
>   
I disagree: A=B "on the blackboard" does mean that every element in A 
equals its positionally-corresponding element in B, and a==b in numpy 
will only be wholly true if a=b in the blackboard sense.  As has been 
said by others in this thread, what needs to be adjusted to (and many 
off-the-shelf numerical programs have operated this way for years, so 
it's not like one has to make this adjustment - if they haven't already 
- only if one is using numpy) is what Robert calls "rich comparisons", 
i.e., a comparison of arrays/matrices returns a boolean-valued but 
otherwise similar object, whose elements indicate whether the comparison 
is true or false at each position.  To determine if the comparison 
returns true for every element, all one has to do is use the 'all' 
method - not a huge amount of overhead, and now rather ubiquitous (in my 
experience) throughout the numerical software community (not to mention 
that rich comparison is _much_ more flexible, and in that, powerful).  
Oh, and another convenience method with which you should be aware is 
'any', which returns true if any of the element-wise comparisons are true.

DG
> I tried to dig up something about this "'a==b' return an array" decision from
> the discussion surrounding PEP 207 (on comp.lang.python or on python-dev) but I
> got lost in that thread.
>
>   




More information about the NumPy-Discussion mailing list