[PYTHON MATRIX-SIG] Some notes on the matrix class

Guido van Rossum guido@CNRI.Reston.VA.US
Wed, 01 Nov 1995 16:08:06 -0500

> The reason for this is that if a = [1,2,3], and b = [2,2,2], I'd
> like to define a>b = [0,0,1].  (where all of the above are
> matrices).  This is useful in an astounding range of matrix
> computations, and there is no sensible definition of a>b for
> matrices that returns a scalar boolean value.

I see that I misunderstood your question.  I'm not sure I like
subsuming the ">" operator (and its companions "<", "<=" etc.) for
this purpose.  In Python it's quite common (well, at least it's
possible) to use comparisons between objects of unknown type.  If I

	def spam(a, b):
		if a < b: ...do something...
		else: ...do something else...

and a and b can be anything.  If for certain types a<b returns a list
(which is always true) this could mess up some invariants that the
code relies on (e.g. exactly one of a<b, a==b, a>b is true).

Currently, it is not possible for comparisons to raise exceptions.
This may change in the future, however, and then matrices (like
complex numbers) should raise some exception to indicate that
comparing them doesn't make.

There is also the comparison chaining (a<b<c) which is implemented at
a rather low level in the language, and again assumes that a<b returns
true or false.

You can always define methods equal, greater and less, where
a.greater(b) = [0,0,1] in your example.

--Guido van Rossum <guido@CNRI.Reston.VA.US>
URL: <http://www.python.org/~guido/>

MATRIX-SIG  - SIG on Matrix Math for Python

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