[Matrix-SIG] Perplexing comparisons

Zane Motteler zcm@llnl.gov
Fri, 11 Sep 1998 14:25:17 -0800


Charles,

You said:

>The following message is a courtesy copy of an article
>that has been posted to comp.lang.python as well.
>
>
>Can anyone enlighten me as to what's going on here?
>
>Python 1.5 (#13, Sep  9 1998, 15:58:11)  [GCC 2.7.2.3] on linux2
>Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>>> t1 = (150,0,1)
>>>> t2 = (149,1,0)
>>>> t1<t2
>0
>>>> t2<t1
>1
>>>> t1>t2
>1
>>>> t2>t1
>0
>>>> a1,a2 = array(t1),array(t2)
>>>> a1<a2
>1
>>>> 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.

>>> less (a1, a2)
array([0, 1, 0])
>>> greater (a1, a2)
array([1, 0, 1])
>>>

Cheers,

Zane

-----------------------------------------------------------------
                      Zane C. Motteler, Ph. D.
Computer Scientist             | Professor Emeritus of
Lawrence Livermore National    |    Computer Science and Engineering
   Laboratory                  | California Polytechnic
P. O. Box 808, L-038           |    State University
Livermore, CA 94551-0808       | San Luis Obispo, CA 93407
925/423-2143, FAX 925/423-9969 | zmottel@hornet.csc.calpoly.edu
zcm@llnl.gov, motteler@icf.llnl.gov
(For FedEx, UPS, etc. use 7000 East Avenue, zip 94550-9234)