title: How do numpy's in-place operations (e.g. `+=`) work?
body: <p>The basic question is: What happens under the hood when doing: <code>a[i] += b</code>?</p>
  
  <p>Given the following:</p>
  
  <pre><code>import numpy as np
  a = np.arange(4)
  i = a &gt; 0
  i
  = array([False,  True,  True,  True], dtype=bool)
  </code></pre>
  
  <p>I understand that:</p>
  
  <ul>
  <li><code>a[i] = x</code> is the same as <code>a.__setitem__(i, x)</code>, which assigns directly to the items indicated by <code>i</code></li>
  <li><code>a += x</code> is the same as <code>a.__iadd__(x)</code>, which does the addition in place</li>
  </ul>
  
  <p><em>But what happens when I do</em>:</p>
  
  <pre><code>a[i] += x
  </code></pre>
  
  <p>Specifically:</p>
  
  <ol>
  <li>Is this the same as <code>a[i] = a[i] + x</code>?  (which is not an in-place operation)</li>
  <li>Does it make a difference in this case if <code>i</code> is:
  
  <ul>
  <li>an <code>int</code> index, or</li>
  <li>an <code>ndarray</code>, or</li>
  <li>a <code>slice</code> object</li>
  </ul></li>
  </ol>
  
  <hr>
  
  <p><em>Background</em></p>
  
  <p>The reason I started delving into this is that I encountered a non-intuitive behavior when working with duplicate indices:</p>
  
  <pre><code>a = np.zeros(4)
  x = np.arange(4)
  indices = np.zeros(4,dtype=np.int)  # duplicate indices
  a[indices] += x
  a
  = array([ 3.,  0.,  0.,  0.])
  </code></pre>
  
  <p>More interesting stuff about duplicate indices in <a href="https://stackoverflow.com/questions/15973827/handling-of-duplicate-indices-in-numpy-assignments/16033516#16033516">this question</a>.</p>