img_1 = np.arange(25).reshape(5,5)
img_2 = img_1
locs = np.where(img_2 >= 0)
img_2[locs] = [65000]
Wondering is there an way to have img_1 with initial array and only img_2 will will be modified?
Both img_1 and img_2 array is changing.
img2 = img1.copy().img2 = img1makesimg2point to the same data asimg1.img2 = img1will makeimg2reference the exact same object asimg1, regardless of whatimg1is. For more on this, see what does it mean by 'passed by assignment'?img2=img1.copy()will give you a copy .. for other objects which donot have a copy() method inplemented ...import copyandobj2=copy.deepcopy(obj1)will give you true copy and not a referenceimg_2[img_2>=0]produces the same result. The argument produces a Boolean for each element of img_2, i.e., accordingly the array img_2 takes the values.