numpy.random.shuffle returns None

前端 未结 4 880
旧时难觅i
旧时难觅i 2021-01-21 10:19

I installed numpy1.8.2 and then I tried the following code:

import numpy as np
a = np.arange(10)
print a, np.random.shuffle(a)

but

4条回答
  •  -上瘾入骨i
    2021-01-21 11:17

    If you want to 'shuffle' out of place then use np.random.permutation.

    e.g.

    In [1]: import numpy as np
    
    In [2]: np.random.permutation([1,2,3,4,5])
    Out[2]: array([3, 5, 1, 4, 2])
    

提交回复
热议问题