numpy基础教程--浅拷贝和深拷贝

在numpy中,使用等号(=)直接赋值返回的是一个视图,属于浅拷贝;要完整的拷贝一个numpy.ndarray类型的数据的话,只能调用copy()函数

# coding = utf-8
import numpy as np
t = np.zeros(24).reshape(4, 6)
t1 = t
t2 = t.copy()
print('t1 is t: {0}'.format(t1 is t))
print('t2 is t: {0}'.format(t2 is t))
t1[0, 2] = 1
print(t)
print("*"*20)
print(t2)

 

猜你喜欢

转载自www.cnblogs.com/romin/p/10124552.html
今日推荐