numpy.random.shuffle returns None

前端 未结 4 878
旧时难觅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条回答
  •  说谎
    说谎 (楼主)
    2021-01-21 11:05

    shuffle works in place and therefore does not return a value.

    In [1]: x = range(9)
    
    In [2]: x
    Out[2]: [0, 1, 2, 3, 4, 5, 6, 7, 8]
    
    In [5]: print numpy.random.shuffle(x)
    None
    
    In [6]: x
    Out[6]: [8, 7, 3, 4, 6, 0, 5, 1, 2]
    

提交回复
热议问题