numpy.random.randint用法
numpy.random.randint(low, high=None, size=None, dtype='l')
1
函數的作用是,返回一個隨機整型數,范圍從低(包括)到高(不包括),即[low, high)。
如果沒有寫參數high的值,則返回[0,low)的值。
參數如下:
low: int
生成的數值最低要大於等於low。(hign = None時,生成的數值要在[0, low)區間內)
high: int (可選)
如果使用這個值,則生成的數值在[low, high)區間。 size: int or tuple of ints(可選)
輸出隨機數的尺寸,比如size = (m * n* k)則輸出同規模即m * n* k個隨機數。默認是None的,僅僅返回滿足要求的單一隨機數。
dtype: dtype(可選):
想要輸出的格式。如int64、int等等
輸出:
out: int or ndarray of ints
返回一個隨機數或隨機數數組
例子
np.random.randint(2, size=10)
array([1, 0, 0, 0, 1, 1, 0, 0, 1, 0])np.random.randint(1, size=10)
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
1np.random.randint(5, size=(2, 4))
array(4, 0, 2, 1], [3, 2, 2, 0)
np.random.randint(2, high=10, size=(2,3))
array(6, 8, 7], [2, 5, 2)
————————————————
版權聲明:本文為CSDN博主「安ann」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/u011851421/java/article/details/83544853
