[MATRIX-SIG] array(a) == array(a)

Timothy A. Hochberg hochberg@wwa.com
Mon, 1 Sep 1997 22:45:30 -0500 (CDT)


On Mon, 1 Sep 1997, Alexander Lawhead wrote:

> I was wondering why testing the equivalence of NumPy arrays 
> doesn't seem to function properly:
>  
> >>> a = range(10)
> >>> a == a
> 1
> >>> array(a) == array(a)          
> 0            
> >>> array(a).tolist() == array(a).tolist()
> 1

Testing equality using == (and <, <=, etc.) of arrays is busted on
purpose. In order to be compatable with the other Numeric functions, these
should return arrays where the arrays are compared element by element. The
next best thing would be to raise an exception. The third best thing would
be to make comparisons so horribly broken that people would notice quickly
and not use them. Since options one and two are not possible for technical
reasons, Jim H. elected to go with option three.  And see, it worked ;)

I believe in Python 1.5, it will be possible to raise an exception, so
perhaps we can upgrade the situation somewhat.

In the meantime, use Numeric.equal to compare element by element, and
you've allready found a way to test for total equality
(alltrue(equal(a,b).flat))  might be faster though.) 

 ____   
  /im  

+------------------------------------------------+
|Tim Hochberg            Research Assistant      |
|hochberg <at> wwa.com   University of Illinois  |
|                        Electrical Engineering  |
+------------------------------------------------+


_______________
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
_______________