借助numpy.random.permutation()方法,可以使用該方法獲得置換序列和返回序列的隨機樣本。
用法:numpy.random.permutation(x)
返回:返回排列值的隨機序列。
範例1:
在此示例中,我們可以看到,通過使用numpy.random.permutation()方法,我們可以獲得排列的序列,並且它將使用此方法返回序列。
Python3
# import numpy
import numpy as np
import matplotlib.pyplot as plt
# Using permutation() method
gfg = np.random.permutation(200)
count, bins, ignored = plt.hist(gfg, 14, density = True)
plt.show()
輸出:
範例2:
Python3
# import numpy
import numpy as np
import matplotlib.pyplot as plt
arr = np.arange(12).reshape((4, 3))
# Using permutation() method
gfg = np.random.permutation(arr)
count, bins, ignored = plt.hist(gfg, 14, density = True)
plt.show()
輸出:
相關用法
注:本文由純淨天空篩選整理自Jitender_1998大神的英文原創作品 numpy.random.permutation() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。