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 很陌生,我正在尝试以最 Pythonic 的方式实现以下目标。所以,我有两个数组:
a=array([[0, 1, 2],[3,4,5]]) b=zeros(a.shape)
现在,我想要的是 b 中的每个元素都比 a 中相应元素的值大一,即 b=a+1
我想知道如何在 numpy 中实现这一点。
最简单的方法如下:
b = a + 1
但是如果你想自己遍历数组(虽然不推荐):
for i in range(len(a)): for j in range(len(a[i])): b[i][j] = a[i][j] + 1