私のnumpy配列の変更で奇妙な動作があります。それはおそらく、Pythonで「通常」の動作ですが、私は本当にこの関連リンク言語に慣れていないです:1つのnumpy配列を変更しますが、2を変更します...?
B=[[1,2,3],[4,5,6],[7,8,9]]
b=np.asarray(B)
c=b
print("I display b :")
print(b)
c[0,0]=-c[0,0] # I multiply this coordinates by -1
print("I display c (modified at the right place : ok)")
print(c)
print("But b has also been modified ???!!!")
print(b)
出力:
I display b :
[[1 2 3]
[4 5 6]
[7 8 9]]
I display c (modified at the right place : ok)
[[-1 2 3]
[ 4 5 6]
[ 7 8 9]]
But b has also been modified ???!!!
[[-1 2 3]
[ 4 5 6]
[ 7 8 9]]
bが、私はそれを変更したことがない場合でも、変更されているのはなぜ?私はただCを変えました...?
'C = B'を** **新しいオブジェクトを作成しません。 – jonrsharpe