我有一个更复杂的程序,这段代码:
import numpy as np
ph=np.arange(6).reshape([2,3])
T=np.transpose(ph)
print 'T:\n',T
print 'ph:\n',ph # printing arrays before for cycle
for i in range(0,len(T)):
T[i]=2*T[i]
print 'ph:\n', ph # printing arrays after for cycle
print 'T:\n',T
我希望在输出 T 和
ph:
[[0 1 2]
[3 4 5]]
相反,我有
ph:
[[ 0 2 4]
[ 6 8 10]]
T:
[[ 0 6]
[ 2 8]
[ 4 10]]
因此,当我在 for cicle 中将 T 的每一行乘以 *2 时,我对 ph 做同样的事情。为什么?