What is this issue of variable affectation in python?
Question: I have this problem in python. I have a function which take the following
inputs

    
    
    import numpy;
    from numpy import *;
    def GetInf(G, X, m, n):
        g           = G[m - 1, :].T;
        Y           = X;
        Y[m - 1, :] = 0;
        Y[:, n - 1] = 0;
        # Here I modify Y. The problem is that X is modified too. Why?
        # In fact, I add Y after I see that X is changing but X keeps changing.
        result      =  sum(Y * G);
        return result;
    
    G = array([[1., 2., 3.], [4., 5., 6.]]);
    X = array([[1., 0., 0.], [0., 0., 1.]]);
    I = GetInf(G, X, 1, 1);
    

My problem is that when I debug the program I see that after modifying `Y`,
`X` is also modified. I cannot understand why.


Answer: it because of that you assign `X` to `Y` . that means `Y` is a reference to
where `X` refer ! if you don't want that you have to make a copy of `X` :

    
    
    Y=np.copy(X)
    

