为什么reshape
在转置后返回新数组,而在未转置时返回视图?它何时返回视图以及何时创建新数组?
a = np.zeros((3,2))
b = a.T.reshape(3*2)
c = a.reshape(3*2)
print(a)
c[2] = 10000
b[0] = 10000
print(a)
print(b)
结果
[[0. 0.]
[0. 0.]
[0. 0.]]
[[ 0. 0.]
[10000. 0.]
[ 0. 0.]]
[10000. 0. 0. 0. 0. 0.]