数组的复制

import numpy
a=numpy.arange(12).reshape(3,4)
b=a[:2,:2]

#对子数组b中值进行修改,将会影响到a数组中的值
b[0][1]=1000
print(a)

[[   0 1000    2    3]
 [   4    5    6    7]
 [   8    9   10   11]]

print(b)

[[   0 1000]
 [   4    5]]

#可以使用numpy中的copy方法,将和原数组脱离关系
c=numpy.copy(a[:2,:2])
print(c)

[[   0 1000]
 [   4    5]]

c[1][1]=120

print(c)

[[   0 1000]
 [   4  120]]

print(a)
[[   0 1000    2    3]
 [   4    5    6    7]
 [   8    9   10   11]]
原文地址:https://www.cnblogs.com/luckiness/p/13151194.html