2
numpy.random.uniform
支持數組參數,但np.random.randint
不會:使用numpy的,以產生具有可變最大/最小隨機整數的序列
import numpy as np
two_random_uniforms = np.random.uniform([0, 1], [3, 4])
this_raises_exception = np.random.randint([0, 1], [3, 4])
我從代碼的第二行想要的行爲等同於:
result = []
for lown, highn in zip([0, 1], [3, 4]):
result.append(np.random.randint(lown, highn))
有沒有辦法用變量max/min來完成隨機整數生成而不用編寫python循環?對於我的應用程序需要的大型數組,上述解決方法將會無法接受。我可以在cython中編寫循環,但如果可能的話,我寧願使用Numpy。