我想輸出類似:[array([-1, 1, -1]), array([-1, 1, 1])] 等 100 次。由于語法無效,我一直在編輯我的代碼但沒有成功。
test = []
i =1
def testdata():
while i<= 100:
new = [random.choices([-1,1], k=3) for _ in range(100)]
test.append(new)
np.array(n) for n in new.values()[:3]
i = 1
return new
uj5u.com熱心網友回復:
import random as r
c = [-1, 1]
[np.array([r.choice(c), r.choice(c), r.choice(c)]) for _ in range(100)]
uj5u.com熱心網友回復:
return np.array(random.choices([-1, 1], k=3*100)).reshape(100, 3)
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/338381.html
下一篇:在滑動視窗中應用np.where
