numpy.random.RandomState.permutation#
方法
- random.RandomState.permutation(x)#
随机排列序列,或返回排列过的范围。
如果 x 是多维数组,则仅沿其第一维进行洗牌。
注意
新代码应改用
Generator
实例的permutation
方法;请参阅快速入门。- 参数:
- xint 或 array_like
如果 x 是整数,则随机排列
np.arange(x)
。如果 x 是数组,则创建副本并随机洗牌元素。
- 返回:
- outndarray
排列过的序列或数组范围。
另请参阅
random.Generator.permutation
应在新代码中使用。
示例
>>> np.random.permutation(10) array([1, 7, 4, 3, 0, 9, 2, 5, 8, 6]) # random
>>> np.random.permutation([1, 4, 9, 12, 15]) array([15, 1, 9, 4, 12]) # random
>>> arr = np.arange(9).reshape((3, 3)) >>> np.random.permutation(arr) array([[6, 7, 8], # random [0, 1, 2], [3, 4, 5]])