NumPy 复制与视图
来源:互联网 发布:实验室洗眼器 淘宝 编辑:程序博客网 时间:2024/05/29 18:25
原文地址:http://blog.csdn.net/lsjseu/article/details/20359201
在原文基础上适当精简并更正少量原作者的笔误:
复制和视图
1. 完全不拷贝
简单的赋值不拷贝数组对象或它们的数据。
>>> a = arange(12)>>> b = a # no new object is created>>> b isa # a and b are twonames for the same ndarray objectTrue>>> b.shape =3,4 # changes the shape of a>>> a.shape(3, 4)
2. Python 传递不定对象作为参考,所以函数调用不拷贝数组。
>>> def f(x):... print id(x)...>>>id(a) # id is aunique identifier of an object148293216>>> f(a)148293216
3.视图(view)和浅复制
不同的数组对象分享同一个数据。视图方法创造一个新的数组对象指向同一数据。
>>> c = a.view()>>> c is aFalse>>> c.baseis a # c is a view ofthe data owned by aTrue>>> c.flags.owndataFalse>>>c.shape = 2,6 # a's shape doesn'tchange>>> a.shape(3, 4)>>> c[0,4]= 1234 # a's datachanges>>> aarray([[ 0, 1, 2, 3], [1234, 5, 6, 7], [ 8, 9, 10, 11]])
4. 切片数组返回原数组的一个视图:
>>> s = a[: , 1:3] # spaces added forclarity; could also be written "s = a[:,1:3]">>> s[:] =10 # s[:] is a view ofs. Note the difference between s=10 and s[:]=10>>> aarray([[ 0, 10, 10, 3], [1234, 10, 10, 7], [ 8, 10, 10, 11]])
5. 深复制:
这个复制方法完全复制数组和它的数据。
>>> d =a.copy() # a new arrayobject with new data is created>>> d is aFalse>>> d.baseis a # d doesn't shareanything with aFalse>>> d[0,0] = 9999>>> aarray([[ 0, 10, 10, 3], [1234, 10, 10, 7], [ 8, 10, 10, 11]])
0 0
- NumPy 复制与视图
- Numpy-复制与视图
- NumPy 复制和视图
- numpy 攻略 2.5 视图与副本
- 高级复制与物化视图的选型
- Numpy-复制操作
- numpy小记,复制array
- NumPy(4)数组数学与基础操作与复制、排序
- 使用numpy复制拓展数据
- numpy.ravel() 与numpy.flatten()
- 复制数据表以及视图
- NumPy之三:拷贝和视图
- numpy中数组元素的切片复制
- numpy.flatten() 与 numpy.ravel()的区别
- numpy 数组与类型
- NumPy与ndarray简介
- python numpy与matplotlib
- Numpy与Pandas排序
- Mysql事务隔离级别与锁
- U盘安装win 10【双系统】
- header 函数
- 趣学 C 语言(十二)—— 文件操作
- Struts2-服务端验证
- NumPy 复制与视图
- Java void关键字
- 自定义圆形进度条
- 什么是JTAG及其使用方法
- js学习笔记(类型检测)
- Java异常处理机制【转载】
- LeetCode:Basic Calculator II
- .NET Framework 中的反射
- MYSQL基础学习(二)