[PYTHON MATRIX-SIG] Some notes on the matrix class
James Hugunin
jjh@mama-bear.lcs.mit.edu
Wed, 1 Nov 95 16:02:31 -0500
> Couldn't this be done by implementing a "numeric" type (at the C
> level) that has a range of [0..1]? It could have two objects...
>
> Also, what exactly is the advantage of having a Boolean type? (Am I
> showing my age here? :-)
What I'm asking for is to be able to create a new python object in C, and
to include boolean methods for that object. So, just like I can implement
my matrix_add function for the syntax "a+b" when a and b are matrices
(modulo coercion), I'd really like to be able to implement a matrix_greater
function for the syntax "a>b" when a and b are matrices (still modulo
coercion). This seems completely in the original spirit of the language.
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.
ie. the traditional discrete delta function is elegantly expressed as
def delta(i): return i==0
delta([-2,-1,0,1,2,3,4]) -> [0,0,1,0,0,0,0]
It's also useful for "vectorizing" traditional operations like filter. If
x is a vector,
filter(lambda x: x<2 and x>0, x) <--> x.filter(x<2 and x>0)
except the second is orders of magnitude faster for matrices.
I understand that this is a major change to some of the more complicated
parts of python, so there are good practical reasons that it won't be done
anytime soon. Nevertheless, I would love though to have you agree that this
would be a good feature if somebody ever has the time to add it.
-Jim
=================
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================