numpy.random.shuffle

原文:https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.shuffle.html

译者:飞龙 UsyiyiCN

校对:(虚位以待)

numpy.random.shuffle(x)

通过随机播放其内容来修改序列。

参数:

x:array_like

要混洗的数组或列表。

返回:

没有

例子

>>> arr = np.arange(10)
>>> np.random.shuffle(arr)
>>> arr
[1 7 5 2 9 4 3 6 0 8]

此函数只沿着多维数组的第一个索引重组数组:

>>> arr = np.arange(9).reshape((3, 3))
>>> np.random.shuffle(arr)
>>> arr
array([[3, 4, 5],
       [6, 7, 8],
       [0, 1, 2]])