
24 Apr
2007
24 Apr
'07
1:23 a.m.
Mark.Miller wrote:
Pierre GM wrote:
a[a<0] = numpy.random.normal(0,1)
This is a neat construct that I didn't realize was possible. However, it has the undesirable (in my case) effect of placing a single new random number in each locations where a<0. While this could work, I ideally need a different random number chosen for each replaced value. Does that make sense?
Certainly. How about this?
mask = (a<0) a[mask] = numpy.random.normal(0, 1, size=mask.sum())
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco