Following is my numpy array.
import numpy as np
arr = np.array([1,2,3,4,5])
arrc=arr
arrc[arr<3]=3
When I run
>>> arrc
output : array([3,3,3,4,5])
>>> arr
output : array([3,3,3,4,5])
I expected changing arrc does not affect arr. However, both array is changing. In my actual code I am changing arrc multiple times so I observe error if arrc have influence to arr. Is there any good way to fix this?
arrc = arr.copy(). Otherwisearrcandarrare references to the same array.arrc=arr- just assigns the same object to the new variable name. It does not make a copy. This isn't just anumpything; it's basic Python. But withnumpyyou also have to know when something is aviewinstead of acopy.