查看: 2121|回复: 0

numpy copy & deep copy

[复制链接]

665

主题

1234

帖子

6678

积分

xdtech

Rank: 5Rank: 5

积分
6678
发表于 2019-4-21 21:14:48 | 显示全部楼层 |阅读模式
import numpy as np

# copy & deep copy

a = np.arange(4)
print(a)
b = a
c = a
d = b

# 改变a[0] 的值
print('******************')
a[0] = 11
print(a)
print(b)
print(b is a)
print('******************')
print(c)
print(c is a)
print('******************')
d[1: 3] = [22,33]
print(d)
print(a)
print(d is a)
print('******************')

# deep copy
b = a.copy()
print(b)
a[3] = 44
print(a)
print(b)
print('******************')

结果:
[0 1 2 3]

[11 1 2 3]
[11 1 2 3]
True

[11 1 2 3]
True

[11 22 33 3]
[11 22 33 3]
True

[11 22 33 3]
[11 22 33 44]
[11 22 33 3]


---------------------


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表