[Numpy-discussion] in place random generation

Robert Kern robert.kern at gmail.com
Mon Mar 19 13:34:50 EDT 2007


Travis Oliphant wrote:
> I've just added a faster path through the random-number generators for 
> scalar parameters to the SVN code tree.
> 
> It would be great if those who use this could check to see if
> 
> 1) it is correct
> 2) it is indeed faster for scalar parameters

It's faster, certainly. I'll check for correctness later. Good work!


In [13]: import timeit

In [14]: tstd = timeit.Timer("random.normalvariate(0, 1)", "import random")

In [15]: tscalar = timeit.Timer("random.normal(0, 1)", "from numpy import random")

In [16]: tarray = timeit.Timer("random.normal(array(0), array(1))", "from numpy
import array, random")

In [17]: tstd.repeat()
Out[17]: [2.700355052947998, 2.6895289421081543, 2.7158269882202148]

In [18]: tscalar.repeat()
Out[18]: [0.60753297805786133, 0.60142016410827637, 0.59989500045776367]

In [19]: tarray.repeat()
Out[19]: [2.0689051151275635, 2.0820560455322266, 2.0542140007019043]


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



More information about the NumPy-Discussion mailing list