I've been struggling with some operations over NumPy arrays and functions in a recent script. I've finally discovered what seems to be the error: NumPy __isub__.
Heres a example:
def test(apocalypse):
apocalypse = apocalypse - 3
return apocalypse
def test2(apocalypse):
apocalypse -= 3
return apocalypse
foo = np.array([1,2,3])
print(test(foo))
print(foo)
bar = np.array([1,2,3])
print(test2(bar))
print(bar)
Which results in:
[-2 -1 0]
[1 2 3]
[-2 -1 0]
[-2 -1 0]
Was it expected? Should -=
change a global variable (same for +=
)? I've tried with int and float instead of NumPy arrays and it worked as I expected.