为什么重整对于Transpose和返回新nd数组的工作方式有所不同?

时间:2019-02-11 15:21:29

标签: python numpy view numpy-ndarray

为什么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.]

0 个答案:

没有答案