python object changes the value of an input variable
Question: So I don't know if this is a well-formed question, and I'm sorry if it isn't,
but I'm pretty stumped. Furthermore, I don't know how to submit a minimal
working example because I can't reproduce the behavior without the whole code,
which is a little big for stackexchange.

So here's the problem: I have an object which takes as one of its arguments a
numpy array. (If it helps, this array represents the initial conditions for a
differential equation which a method in my object solves numerically.) After
using this array to solve the differential equation, it outputs the answer
just fine, BUT the original variable in which I had stored the array has now
changed value. Here is what I happens:

    
    
    import numpy as np
    import mycode as mc
    
    input_arr = np.ndarray(some_shape)
    foo = mc.MyClass(input_arr)
    foo.numerical_solve()
    some_output
    

Fine and dandy. But then, when I check on `input_arr`, it's changed value.
Sometimes it's the same as `some_output` (which is to say, the final value of
the numerical solution), but sometimes it's some interstitial step.

As I said, I'm totally stumped and any advice would be much appreciated!


Answer: If you have a mutable object (`list`, `set`, `numpy.array`, ...) and you do
not want it mutated, then you need to make a copy and pass that instead:

    
    
    l1 = [1, 2, 3]
    l2 = l1[:]
    
    s1 = set([1, 2, 3])
    s2 = s1.copy()
    
    arr1 = np.ndarray(some_shape)
    arr2 = np.copy(arr1)
    

