NumPy 没有复制
2021-11-06 17:33 更新
简单赋值不会复制对象或其数据。
>>> a = np.array([[ 0, 1, 2, 3],
... [ 4, 5, 6, 7],
... [ 8, 9, 10, 11]])
>>> b = a # no new object is created
>>> b is a # a and b are two names for the same ndarray object
True
Python 将可变对象作为引用传递,因此函数调用不会进行复制。
>>> def f(x):
... print(id(x))
...
>>> id(a) # id is a unique identifier of an object
148293216 # may vary
>>> f(a)
148293216 # may vary
以上内容是否对您有帮助:
更多建议: