[PYTHON MATRIX-SIG] Some notes on the matrix class
Hinsen Konrad
hinsenk@ere.umontreal.ca
Thu, 2 Nov 1995 09:46:55 -0500
2. ranf(m) fills m with uniform random numbers on (0.0, 1.0)
I'd prefer a matrix constructor (similar to mrange) that creates
a random matrix with a given shape.
b. compress(condition, x) = those elements of x corresponding to those
elements of condition that are "true". condition and x must have
A useful generalization of this, especially since booleans are just
integers in Python, would be a function that replicates each item of x
n times, where n is the corresponding item in the "condition"
argument.
the same length (or x scalar), result is a one-dimensional vector with
length equal to the number of true elements in condition. Naturally this
Why should this be restricted to one-dimensional arguments? Of course
the "condition" argument must be one-dimensional, but the compression
(or copying, in the sense outlined above) can occur along any axis
of a multidimensional array.
is most useful if x < y returns a vector instead of a scalar.
Indeed...
c. My Basis users love:
where(condition,x,y) is shaped like condition and has elements of x and
y where condition is respectively true or false; we allow broadcast of
If Python had a selection operator similar to C's ?:, this would be
its generalization to array arguments. And in fact I'd love to have
such an operator in Python in general...
(That sound you hear is the shot of a large caliber weapon as Guido
justifiably shoots a newbie for making a suggested language change before
he can even use half the language yet; in fact, I'm tempted to shoot
myself, but I'm enjoying Python too much to die yet.)
It would be more in the spirit of Python to use poisonous snakes instead
of guns ;-)
-------------------------------------------------------------------------------
Konrad Hinsen | E-Mail: hinsenk@ere.umontreal.ca
Departement de chimie | Tel.: +1-514-343-6111 ext. 3953
Universite de Montreal | Fax: +1-514-343-7586
C.P. 6128, succ. Centre-Ville | Deutsch/Esperanto/English/Nederlands/
Montreal (QC) H3C 3J7 | Francais (phase experimentale)
-------------------------------------------------------------------------------
=================
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================