随机排列一个序列,返回一个排列的序列。
>>> 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]])
本文介绍如何使用numpy库中的random.permutation函数来实现序列的随机排列。该函数可以接受整数或序列作为参数,并返回一个随机排列后的序列。示例展示了对不同类型的输入进行操作的结果。
3万+

被折叠的 条评论
为什么被折叠?



