Why is add and assign (+=) behaving strangely with numpy.ndarrays? <p>consider the following Python code:</p> <pre><code>import numpy a = numpy.random.rand(3,4) b = numpy.random.rand(3,4) c = a c += b c/2. - (a + b)/2. </code></pre> <p>The result of the last line is not an array with zeros. However, if I do:</p> <pre><code>d = a d = d + b d/2. - (a + b)/2. </code></pre> <p>Then the result is 0, as expected. This looks strange to me, can anybody please explain this behaviour? Is it wise to use <code>+=, /=, ...</code> for numpy arrays at all? Thank you!</p> <p>(This is only a minimal example, I have to add up several arrays.)</p>