[Numpy-discussion] in place random generation

Mark P. Miller mpmusu@cc.usu....
Fri Mar 9 10:35:25 CST 2007


This discussion has much in common with a previous thread that I started 
("When and where to use Numpy...").

I fully admit to being a naive numpy user, but it seems to me that it 
would be helpful if the documentation provided some explicit statements 
to inform potential users about the best types of situations where numpy 
will be useful.  And it would be even better if it could be pointed out 
where just using pure python will be advantageous!

As an aside, are the random number generators from scipy.random the same 
as those for numpy.random?  If not, will those of us who need to just 
use a few random numbers here and there throughout our code (we don't 
need arrays of random numbers or broadcasting abilities) benefit more 
from using those libraries?

Anne Archibald wrote:
> On 08/03/07, Charles R Harris <charlesr.harris@gmail.com> wrote:
> 
>> For normals this seems overkill as the same result can be achieved by an
>> offset and scale, i.e., if r is an array of random numbers with mean 0 and
>> sigma 1, then
>>
>> myrandomarray = (r*mysigma + mymean)
>>
>> easily achieves the same result. Other distributions don't have such happy
>> properties, unfortunately, and will have high overhead regardless. For
>> instance, Poisson distributions require a computation of new internal
>> parameters for each value of the mean and doing this on an item by item
>> basis over a whole array is a terrible idea. Hmm, I am not convinced that
>> broadcasting is going to buy you much except overhead. Perhaps this problem
>> should be approached on a case by case basis rather than by some global
>> scheme.
> 
> Whether it's efficient or not in terms of CPU time, it's extremely
> handy to be able to do
> photons = numpy.random.poisson(0.1*cos(omega*numpy.arange(1000000)+0.9)
> 
> Of course I'd prefer if it ran faster, but many of numpy's operations
> are notably slower than the same operation on (say) python lists (try
> the Programming Language Shootout sometime...); their real advantage
> is that they allow programs to be written quickly and clearly.
> 
> Anne
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion


More information about the Numpy-discussion mailing list