[PYTHON MATRIX-SIG] missing (?) feature

Konrad HINSEN hinsenk@ere.umontreal.ca
Mon, 11 Mar 1996 09:08:55 -0500


> Basically, my problem is that I want to do something like:
> 
> 	ranf = Ranf.ranf
> 	age = age + 1
> 	x = age.greater(MAX_AGE).choose(x, ranf)
> 	y = age.greater(MAX_AGE).choose(y, ranf)
> 	age = age.greater(MAX_AGE).choose(age, 0)

If you are really worried about efficiency, you should certainly
not recalculate age.greater(MAX_AGE) three times ;-)

> With the current implementation I have to do:
> 
> 	x = age.greater(MAX_AGE).choose(x, random_sample(NUM_DOTS))
> 
> which is wasteful since on a given iteration, only a few of the dots are
> likely to be "too old".  But a new random_sample() array is generated
> each time anyway.

Which "waste" are you worried about? The waste in CPU time caused by
the random generator? Unless your array is really big, this is
probably not worth mentioning.

On the other hand, a rather concise solution could be obtained if
the idea of allowing general list indices is taken up again.
Then you could write:

   update = repeat(greater(age, MAX_AGE), arrayRange(len(age)))
   x[update] = random_sample(len(update))
   y[update] = random_sample(len(update))

-------------------------------------------------------------------------------
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
=================