[Numpy-discussion] is shuffle needlessly slow?
josef.pktd at gmail.com
josef.pktd at gmail.com
Tue Jan 26 14:20:59 EST 2010
On Tue, Jan 26, 2010 at 2:00 PM, Alan G Isaac <aisaac at american.edu> 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
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
maybe because shuffle works with python objects and random_sample with floats
>>> a=['a','bb','cc','c','a'];np.random.shuffle(a);a
['c', 'a', 'bb', 'a', 'cc']
>>> np.random.random_sample(5)
array([ 0.02791159, 0.8451104 , 0.51629232, 0.15428393, 0.39491844])
Josef
>>>
More information about the NumPy-Discussion
mailing list