区分清楚我们是与共享的视图打交道还是获得数据的一个副本。一个切片代表一个视图,如果把一个切片赋值给另一个变量,随后改变切片在数组中的内容,那么这个变量值也会改变。
“`python
author = ‘guoguo’
encoding:utf-8
import scipy.misc
import matplotlib.pyplot
lena=scipy.misc.lena()
acopy=lena.copy()#创建一个副本
aview=lena.view()#创建一个视图
drawing
matplotlib.pyplot.subplot(221)
matplotlib.pyplot.imshow(lena)
matplotlib.pyplot.subplot(222)
matplotlib.pyplot.imshow(acopy)
matplotlib.pyplot.subplot(223)
matplotlib.pyplot.imshow(aview)
aview.flat=0#flat迭代器,视图中所有值都会清零
matplotlib.pyplot.subplot(224)
matplotlib.pyplot.imshow(aview)
matplotlib.pyplot.show()
“`