I have a class "test" of which I declare two instances, and on which I call an "update" function. "test.a" is a numpy array.
b1 = test()
b1.randomize(2, 0, 0, 0, 0, 0)
b2 = test()
b2.randomize(6, 0, 0.5, 0, 0, 0)
print(b1.a)
print(b2.a)
update(b1,b2)
print(b1.a)
print(b2.a)
The update function is defined as below. The issue is that the value of b2.a changes after the call of update, despite never assigning it therein. I also never made an assignment like "b2.a = b1.a", which would change the reference of b2.a. The class definition is also copied in below.
def update(b1, b2):
dx = b1.p[0,0] - b2.p[0,0]
dy = b1.p[0,1] - b2.p[0,1]
b1.a[0,0] += (-dx) * b2.m
b1.a[0,1] += (-dy) * b2.m
class test:
m = 1.0
r = 0.1
p = np.zeros((1,2))
v = np.zeros((1,2))
a = np.zeros((1,2))
def randomize(self, m_mean, m_stddev, pos_mean, pos_stddev, v_mean, v_stddev):
self.m = np.random.normal(loc = m_mean, scale = m_stddev)
self.p = np.random.normal(loc = pos_mean, scale = pos_stddev, size = (1,2))
self.v = np.random.normal(loc = v_mean, scale = v_stddev, size = (1,2))