[Numpy-discussion] is shuffle needlessly slow?

Alan G Isaac aisaac at american.edu
Tue Jan 26 14:23:24 EST 2010


On 1/26/2010 2:00 PM, Alan G Isaac wrote:
> Is this a fair test?
> I expected shuffle to be much faster
> (no array creation).
> Alan Isaac
>
>>>> import timeit
>>>>
>>>> setup = """
> ... import numpy as np
> ... prng = np.random.RandomState()
> ... N = 10**5
> ... indexes = np.arange(N)
> ... """
>>>>
>>>> print timeit.timeit('prng.shuffle(indexes)',setup, number=100)
> 5.69172311006
>>>> print timeit.timeit('indexes = prng.random_sample(N).argsort()',setup, number=100)
> 1.54648202495


I suppose that is not fair.
But how about this?
>>> print timeit.timeit('indexes[prng.random_sample(N).argsort()]=indexes',setup, number=100)
1.76073257914

Alan Isaac



More information about the NumPy-Discussion mailing list