I am making a certain class for specific purpose ( this time partilce simulation ) when I declare two distinict objects with that class, they themselves share different memory addresses, but their attributes share THE SAME address, which leads to modifying any of them to modify the other, any help? I am stuck.
The code logic-error block:
# Particle is the class
particle1 = Particle(m = 2)
particle2 = Particle(m = 4)
# object.S is an atrribute
particle1.S[1]=np.array([0,1,32])
particle2.S[1]=np.array([2,0,3])
hex(id(particle1.S))==hex(id(particle2.S)) # returns True
And here it is the constructor:
def __init__(self, m = 0, Q = 0, initS = np.array([[0,0,0],[0,0,0],[0,0,0]]) ):
self.initS = initS
self.S = self.initS
self.m = m; self.t = 0
self.charge = Q