On Mon, Apr 18, 2011 at 17:08, Russell E. Owen <rowen@uw.edu> wrote:
I stumbled across code that looks like this:
imageArr = # a 2-d array of floats noiseArr = numpy.random.poisson(imageArr)
This works fine in numpy 1.5.1 and seems to do what I would hope: return an array of random ints whose "expectation of interval" is set by the corresponding element of the input array. Very nice!
However, I can't find any documentation supporting this usage. The standard help says:
poisson(lam=1.0, size=None)
Draw samples from a Poisson distribution.
The Poisson distribution is the limit of the Binomial distribution for large N.
Parameters ---------- lam : float Expectation of interval, should be >= 0. size : int or tuple of ints, optional Output shape. If the given shape is, e.g., ``(m, n, k)``, then ``m * n * k`` samples are drawn.
Which suggest that Iam must be a scalar.
So... is the usage of passing in an array for Iam actually supported/safe to use?
Yes, it is safe. All of the univariate distribution parameters will broadcast against each other as they would with ufuncs. I don't think we do it for multinomial and a couple of the other ones where the semantics would have made my head hurt.
And is there some general rule I could have used to predict that?
Just the one I stated, which is limited to numpy.random. It might even be documented somewhere. Unfortunately, most of the individual methods had their parameters documented before this capability was added. -- 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