[Matrix-SIG] Perplexing comparisons

David Ascher da@skivs.ski.org
Fri, 11 Sep 1998 14:31:13 -0700 (PDT)


> >Can anyone enlighten me as to what's going on here?

> >>>> a2<a1
> >1
> >>>> a1>a2
> >0
> >>>> a2>a1
> >0
> 
> What's probably being compared here is something esoteric,
> e. g. the addresses of the objects or some such. If you actually
> want to do element-by-element comparisons of arrays, use
> the functions 'greater', 'less', etc.

Note that this is somewhat moot -- the latest versions of NumPy should
prevent this anyway: 

>>> a1, a2 = array(t1), array(t2)
>>> a1 < a2
Traceback (innermost last):
  File "<stdin>", line 1, in ?
TypeError: Comparison of multiarray objects is not implemented.

There are plans for a 'rich comparison' which would return in your case
the array (0,0,0) for a1 < a2, and (1,0,0) for (a2 < a1).  

--david