Strange things happens today when I do things like this:
a = np.array([1, 2, 3])
b = a
b[0] = 0
print a, b
And then the value seems to be passed by reference! The answer becomes:
result: [0 2 3] [0 2 3]
But usually I think the variable in python is passed by value, like this:
a = np.array([1, 2, 3])
b = a
b = np.array([0, 2, 3])
print a, b
And then the answer becomes:
result: [1 2 3] [0 2 3]
But why is that happenning? How do I decide whether the variable is passed through reference or value? Some people said it was because of the mutable object, but I still don't quite get it. So can you explain it for me? Thanks a lot!