我今天发现了一件奇怪的事情,并想知道是否有人可以了解这里的差异是什么?
import numpy as np
A = np.arange(12).reshape(4,3)
for a in A:
a = a + 1
B = np.arange(12).reshape(4,3)
for b in B:
b += 1
Run Code Online (Sandbox Code Playgroud)
运行每个for循环后,A没有更改,但B已经添加了一个元素.我实际上使用该B版本写入for循环内的初始化NumPy数组.