上一个主题

numpy.random.shuffle

下一个主题

numpy.random.beta

numpy.random.permutation

numpy.random.permutation(x)

随机排列序列,或返回排列范围。

如果 x 是一个多维数组,它只沿第一个索引无序排列。

参数:
x : int或array类

如果 x 是一个整数,随机排列 np.arange(x) .如果 x 是一个数组,制作一个副本并随机地对元素进行无序排列。

返回:
out : 恩达雷

排列序列或数组范围。

实例

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