NumPy隨機數函式

2021-08-09 21:57:30 字數 669 閱讀 6325

import numpy as np

a = np.random

.rand(3, 4, 5) # 每個元素為0-1之間的浮點數

sn = np.random

.randn(3, 4, 5) # 每個元素是根據n(0, 1)的方式選取出來的浮點數

b = np.random

.randint(100, 200, (3, 4)) # 每個元素為100-200間的整數

import numpy as np

a = np.random

.randint(100, 200, (3, 4))

np.random

.shuffle(a) #a的行重排,a改變

np.random

.permutation(a) #a的行重排,a不變

b = np.random

.randint(100, 200, (8, ))

np.random

.choice(b, (3, 2))

np.random

.choice(b, (3, 2), replace = false

np.random

.choice(b, (3, 2), p = b / np.sum(b))

numpy常用隨機數函式

numpy.random模組裡有各種隨機數生成函式,介紹幾個常用的 randint low,high none,size none,dtype l lowhigh取值範圍,包括下限數值但不包括上限數值,若只有乙個引數,表示取值範圍上限 size生成隨機數的數量或shape,預設時只返回單個隨機數 i...

NumPy的隨機數函式

numpy的random子庫 np.random.np.random.rand 3,4,5 建立 0,1 之間的3維隨機浮點數陣列,均勻分布 np.random.randn 3,4,5 建立3維隨機數陣列,標準正態分佈 np.random.randint 100,200,3,4 建立 100,200...

NumPy的隨機數函式

rand 格式 np.random.rand d0,d1,dn 說明 根據d0 dn建立隨機數陣列,浮點數,0,1 均勻分布 舉例 np.random.rand 3,5,4 randn 格式 np.random.randn d0,d1,dn 說明 根據d0 dn建立隨機數陣列,標準正態分佈 舉例 n...