title: Replacing part of a 2D numpy array using indexing
body: <p>I am trying to replace part of a 2D numpy array named "S" as a function of i and j. Given S as:</p>
  
  <pre><code>&gt;&gt;&gt; S
  Out[1]: 
  array([[ 1.,  0.,  0.],
        [ 0.,  3.,  0.],
        [ 0.,  0.,  9.]]
  </code></pre>
  
  <p>for i= 0 and j= 1, I can access elements row i and j and column i and j using the following syntax:</p>
  
  <pre><code>&gt;&gt;&gt; S[:, [i, j]][[i, j], :]
  Out[2]: 
  array([[ 1.,  0.],
        [ 0.,  3.]])
  </code></pre>
  
  <p>Now when I try to replace the same elements of array S with another array of same dimensions (tmp_arr) python does not give an error but it also does not do anything meaning that the elements of S remain unchanged and no error message is displayed.</p>
  
  <pre><code>&gt;&gt;&gt; tmp_arr
  Out[3]: 
  array([[ 555.,  0.],
         [ 0.,  555.]])
  
  &gt;&gt;&gt; S[:, [i, j]][[i, j], :] = tmp_arr
  </code></pre>
  
  <p>and what I get is the same matrix:</p>
  
  <pre><code>&gt;&gt;&gt; S
  Out[4]: 
  array([[ 1.,  0.,  0.],
        [ 0.,  3.,  0.],
        [ 0.,  0.,  9.]])
  </code></pre>
  
  <p>Obviously the following would work but I am looking for an elegant solution:</p>
  
  <pre><code>S[i, i] = tmp_arr[0, 0]
  S[i, j] = tmp_arr[0, 1]
  S[j, i] = tmp_arr[1, 0]
  S[j, j] = tmp_arr[1, 1]
  </code></pre>
  
  <p>I appreciate your comments and experiences.</p>