This is hard for me to understand:
import numpy
f=numpy.array([1,2])
g=f
g[0]=f[0]+1
print(f)
The output of this code is [2,2]. How can I change the value of g without changing f?
This is because the way pointer work, you need to copy the variable not make a reference to it
In [16]: import copy
In [17]: import numpy
...: f=numpy.array([1,2])
...: g=copy.deepcopy(f)
...: g[0]=f[0]+1
...: print(f)
...:
...:
[1 2]
In [18]: f
Out[18]: array([1, 2])
In [19]: g
Out[19]: array([2, 2])
fandgare different, but they are just two different names for the same object. Python's=creates names.