I've created a simple class with object that has init value x0. When I change another value x, my x0 is also changing.
I thought that x0 should remain unchanged. Could you please explain why is this happening?
file main.py:
import numpy as np
from simpleclass import test
def main():
params = dict()
params['position'] = np.array([1.0, 2.0])
object = test(params)
print(object.x0)
print(object.x)
object.run(2)
print(object.x0)
print(object.x)
if __name__ == "__main__":
main()
file simpleclass.py:
class test():
def __init__(self, params):
self.x0 = params['position']
self.x = self.x0
def run(self, num):
self.x += self.x*num
result:
[ 1. 2.]
[ 1. 2.]
[ 3. 6.]
[ 3. 6.]