I have a class where I defined a numpy array and then I created a copy of an object of that class:
import numpy as np
import copy as cp
class Test():
x=5
arr=np.array([5,3])
TEST_1=Test()
TEST_2=cp.copy(TEST_1)
If I change the value of x for TEST_1 it's ok, it doesn't affect TEST_2:
print(TEST_2.x)
TEST_1.x+=1
print(TEST_2.x)
>>>5
>>>5
But if I try to change the array of TEST_1 it also changes the array of TEST_2:
print(TEST_2.arr)
TEST_1.arr+=np.array([1,1])
print(TEST_2.arr)
>>>[5 3]
>>>[6 4]
I know it's because I have to create a copy of the array, but I don't know how to tell Python to do it when the array it's inside a class.
Thank you and sorry for the bad English.