您的位置:首页 > 编程语言 > Python开发

创建视图和副本

2015-09-20 22:13 549 查看
区分清楚我们是与共享的视图打交道还是获得数据的一个副本。一个切片代表一个视图,如果把一个切片赋值给另一个变量,随后改变切片在数组中的内容,那么这个变量值也会改变。

“`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()

“`
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python numpy