I am trying to make a copy of a numpy array in python. I would then like to change some values of the new array, however somehow this also changes the original?
Why is the following code not correct?
import numpy as np
a = np.array([1,1])
print("Array a:",a)
b = a
b[0] = a[0]*2
print("Array b after manipulation:", b)
print("Array a, after manipulating array b", a)
The only way I can make it work is by list comprehensions.
import numpy as np
a = np.array([1,1])
print("Array a:",a)
b = [x for x in a]
b[0] = a[0]*2
print("Array b after manipulation:", b)
print("Array a, after manipulating array b", a)