09 Array copy of Python Numpy library

09 Array copy

b = np.arange(1,13).reshape((3,4))
print(a)

sub_a = a[:2,:2]  #获取第一、二行,第一、二列
print(sub_a)

Modify the value of the first row and second column

sub_a[0][0] = 100 # 数组进行深拷贝对原数组也进行了修改
print(sub_a)
print(a)

sub_aa = np.copy(a[:2][:2])  # 数组进行深拷贝不对原数组影响
sub_aa[0,0] = 222
print(sub_aa)
print(a)
Published 36 original articles · liked 0 · visits 638

Guess you like

Origin blog.csdn.net/Corollary/article/details/105377734