一、np.random.permutation(x) 不在原数组上进行,不改变自身数组,返回新的数组。
x:数字、N维数组
#输入数字x,对1-x排序
np.random.permutation(10)
>>>array([1, 7, 4, 3, 0, 9, 2, 5, 8, 6]) # random
#输入以为数组x,打乱x排序
np.random.permutation([1, 4, 9, 12, 15])
>>>array([15, 1, 9, 4, 12]) # random
输入N维数组x,打乱N为数组
arr = np.arange(9).reshape((3, 3))
np.random.permutation(arr)
>>>array([[6, 7, 8], # random
[0, 1, 2],
[3, 4, 5]])
二、np.random.shuffle(x) :在原数组上进行,改变自身序列,无返回值。
x:数字、N维数组
#数字
arr = np.arange(10)
#数组
np.random.shuffle(arr)
>>> arr
[1 7 5 2 9 4 3 6 0 8] # random
#高维数组,仅打乱第一维度
>>> arr = np.arange(9).reshape((3, 3))
>>> np.random.shuffle(arr)
>>> arr
array([[3, 4, 5], # random
[6, 7, 8],
[0, 1, 2]])