Had*_*adi 1 python numpy pycharm
我安装了numpy1.8.2,然后尝试了以下代码:
import numpy as np
a = np.arange(10)
print a, np.random.shuffle(a)
Run Code Online (Sandbox Code Playgroud)
但它的输出是:
[0 1 2 3 4 5 6 7 8 9] None
我不知道为什么它会返回None,根据它的文档,它应该可以工作!我不知道问题所在。
我PyCharm 3.1在Windows 7上使用。
Wil*_*ill 11
如果您想“随机播放”,请使用np.random.permutation.
例如
In [1]: import numpy as np
In [2]: np.random.permutation([1,2,3,4,5])
Out[2]: array([3, 5, 1, 4, 2])
Run Code Online (Sandbox Code Playgroud)
shuffle 工作到位,因此不返回值。
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]
Run Code Online (Sandbox Code Playgroud)