[PYTHON MATRIX-SIG] Array comparisons, and determinants
tim@lassi.ece.uiuc.edu
tim@lassi.ece.uiuc.edu
Fri, 25 Oct 1996 12:29:55 -0500
Geoffrey Furnish = G>
Konrad Hinsen = K>
Fredrik Lundh = F>
G>The original poster's request has a utility which I think is being
G>missed. The goal of expecting x >= 0 (or any other operator) to mean
G>x[i] >= 0 for every i, is not to get back a truth value, it is to get
G>back a boolean mask.
The point is not that I (we) think this is a bad idea (I do, but am
willing to be convinced), just that its not possible without a
nontrivial revamping of the python core.
K> But that is far from a trivial change.
F>Not sure about that, really (thought it might add some overhead for
F>classes that only implements __cmp__). Is definitely worth
F>investigating for 1.5.
I agree that this probably wouldn't be that hard. However, I'm not
convinced yet that generalizing the comparison ops would be a "good
thing". My current thinking is that using ufuncs would be better -
keep the comparison ops as returning boolean values.
In any event, I think the important question is what functionality we
give cmp NOW for array objects.
1) We can go ahead and make ==/!= work now as returning 1/0 for arrays
where all elements are equal and 0/1 where they're not.
2) We can deliberately cripple cmp so that it does nothing
useful. This leaves the door open doing something fancy involving
returning arrays later if __equal__, __lessthan__, etc. show up at a
later date..
If we do 1), we're locked into using the comparison operators to
return boolean values. I personally think this is the right way to go.
If we decide later we need the array mask functioniality we can stick
it in a subclass of array (surely by then arrays will be an extension
class...).
If we do 2), we really should have a boolean function that operates on
arrays and tells us if they're the same, i.e:
if not identical(A1, A2):
do_some_stuff(A1, A2)
--
-tim
+--------------------------------------------------------------------+
| Tim Hochberg Ultrahigh Speed Digital Electronics Lab |
| tim@lassi.ece.uiuc.edu University of Illinois |
| http://dogbert.ece.uiuc.edu/~tim (217) 333-6014 |
+--------------------------------------------------------------------+
=================
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================