[Numpy-discussion] strange behaviour with numpy arrays
antlarac
antlarac at gmail.com
Wed Sep 11 06:33:52 EDT 2013
Hi, I have a numpy array, and I want to create another variable equal to it,
to back it up for later calculations, because the first array will change.
But after the first array changes, the second automatically changes to the
same value. An example of what happens:
import numpy as np
a=np.zeros((4,4))
b=a
print(b)
a[3,3]=3
print(' ')
print(b)
gives the result:
[[ 0. 0. 0. 0.]
[ 0. 0. 0. 0.]
[ 0. 0. 0. 0.]
[ 0. 0. 0. 0.]]
[[ 0. 0. 0. 0.]
[ 0. 0. 0. 0.]
[ 0. 0. 0. 0.]
[ 0. 0. 0. 3.]]
As you can see, when the value of a changes, the value of b automatically
changes, even when this is not asked. Is there a way of avoiding this?
This problem does not happen with normal python variables.
Thank you for your time.
--
View this message in context: http://numpy-discussion.10968.n7.nabble.com/strange-behaviour-with-numpy-arrays-tp35123.html
Sent from the Numpy-discussion mailing list archive at Nabble.com.
More information about the NumPy-Discussion
mailing list