|
import numpy as np
# copy & deep copy
a = np.arange(4)
print(a)
b = a
c = a
d = b
# 改变a[0] 的值
print('******************')
a[0] = 11
print(a)
print(b)
print(b is a)
print('******************')
print(c)
print(c is a)
print('******************')
d[1: 3] = [22,33]
print(d)
print(a)
print(d is a)
print('******************')
# deep copy
b = a.copy()
print(b)
a[3] = 44
print(a)
print(b)
print('******************')
结果:
[0 1 2 3]
[11 1 2 3]
[11 1 2 3]
True
[11 1 2 3]
True
[11 22 33 3]
[11 22 33 3]
True
[11 22 33 3]
[11 22 33 44]
[11 22 33 3]
---------------------
|
|