[PYTHON MATRIX-SIG] ARRAY COMPARISONS
Alistair Mees
alistair@maths.uwa.edu.au
Fri, 25 Oct 1996 18:13:36 +0800
tim@lassi.ece.uiuc.edu writes:
>
> >ARRAY COMPARISONS
> >
> >There has been quite a bit of discussion of array comparisons recently. I
> >seem to have missed the early stages so perhaps this has all been dealt
> >with, but just in case...
> >
> >
> >Inequalities are often generalised to work for vectors and matrices. For
> >example, x>=0 where x is a vector means x[i]>=0 for every i.
> >Unfortunately M>=0 where M is a matrix sometimes means the analogous thing
> >to x>=0 and sometimes means M is positive semi-definite. Either of these
> >would presumably be implementable by defining suitable __cmp__ functions.
>
> The problem is that __cmp__ can only validly return an integer. Notice
> that for your first example that am array might be neither >=0 nor <0
> ([1,-1] comes to mind), so there's really no valid value to return.
That is not a problem. The answer to "is [1,-1]>=0" is "no" so you return
0, as you do for the comparisons [1,-1]<=0, [1,-1]>0 and [1,-1]<0. These
are standard elementary results! Likewise, if we are working with
symmetric matrices then A>=B and A<=B can both return 0 (since they are
equivalent to A-B>=0 and A-B<=0, neither of which might be true if we
decide to define the inequalities to be statements about positive
semidefiniteness.
It seems to me that one of the reasons APL never made it was that it
insisted on talking its own language which was internally self-consistent
but had little to do with any language talked by others. Conversely,
Matlab, with its horrid "bad Fortran" syntax, is very popular in part
because it never strays really far from standard notation. If we are to
sell NumPy to users, shouldn't we try to make the operators mean what
typical users will expect them to mean, or will learn that they mean in
mathematics courses, rather than defining them to be something completely
different?
The natural place for M>=0 to mean M is positive semidefinite would be in
Matrix, would it not? This is in any case a less important point. The
natural place for x>=0 to be defined for rank 1 arrays x (assuming we are
stuck with single integer returns) is in Numeric. It would be consistent
to use the same definition with any rank of array, assuming __cmp__ is too
rigidly defined to allow an array result.
Alistair
=================
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================