I am new to python, previously was using Matlab, and have some confusion regarding variables in python.
I am trying to rewrite a Matlab code in python, and here is where confusion happens. Lets say I have the following case:
>>> A = np.array([[1,2,3],[4,5,6]])
>>> out = np.array([[True, False, True],[False, True, False]])
>>>
>>> B = A
>>>
>>> B[out] = A[out]+1
>>>
>>> B
array([[2, 2, 4],
[4, 6, 6]])
>>> A
array([[2, 2, 4],
[4, 6, 6]])
In Matlab, A does not change with the same piece of code, but in python, it does. Anyone can explain why and what is the best way to avoid the change of A?
Code-image: why assigning A to B is kept in the flow?