非副本视图的子视图
import numpy as np
>> x = np.array([[12,5,2,4],
[7,6,8,8],
[1,6,7,7]])
array([[12, 5, 2, 4],
[ 7, 6, 8, 8],
[ 1, 6, 7, 7]])
1.取前2行,前2列
>> x_sub = x[:2,:2]
array([[12, 5],
[ 7, 6]])
2.修改x_sub
>> x_sub[0][0] = 99
>> print(x_sub)
[[99 5]
[ 7 6]]
3.此时打印原来的x,发现x也被修改了
>> print(x)
[[99 5 2 4]
[ 7 6 8 8]
[ 1 6 7 7]]
网友评论