Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我是 numpy 的新手。创建一个新数组并用一定范围内的随机数填充每个元素的最佳方法是什么?
例如,我想要一个3×3数组,其中每个元素都是 a0或 a 1。
0
1
尝试类似的东西
np.random.randint(2, size=(3, 3))
有关详细信息,请参阅此文档。
例如:
import numpy as np print np.random.randint(2, size=(3, 3))
输出:
[[1 0 0] [1 1 0] [1 0 0]]