In python, there is a difference between an object and a variable. A variable is name assigned to an object; and an object can have more than one name in memory.
By doing pic1 = pic; pic2 = pic
, You're assigning the same object to multiple different variable names, so you end up modifying the same object.
What you want is to create copies using np.ndarray.copy
—
pic1 = pic.copy()
pic2 = pic.copy()
Or, quite similarly, using np.copy
—
pic1, pic2 = map(np.copy, (pic, pic))
This syntax actually makes it really easy to clone pic
as many times as you like:
pic1, pic2, ... picN = map(np.copy, [pic] * N)
Where N
is the number of copies you want to create.