title: Modifying a part of the main diagonal of a 2d-numpy array
body: <p>I'm having problems with the following task.</p>
  
  <p>Assume we have a matrix, looking like this:</p>
  
  <pre><code>Mat = np.array([
      [11, 12, 13, 14, 15], \
      [21, 22, 23, 24, 25], \
      [31, 32, 33, 34, 35], \
      [41, 42, 43, 44, 45], \
      [51, 52, 53, 54, 55]])
  </code></pre>
  
  <p>What I want to do is to replace the entries 22, 33 and 44 with something different that I calculated before. I know I could do this with for loops but I think there has to be a more elegant way.</p>
  
  <p>I have something like this in mind:</p>
  
  <ol>
  <li>Subselect the main diagonal from [1,1] to [-2,-2] and save it as an array.</li>
  <li>Modify this array in the desired manner.</li>
  <li>Save the modified array as part of the main diagonal of the matrix.</li>
  </ol>
  
  <p>I found the <strong>np.diagonal()</strong> to get the diagonal and got so far:</p>
  
  <pre><code>Mat = np.array([
  [11, 12, 13, 14, 15], \
  [21, 22, 23, 24, 25], \
  [31, 32, 33, 34, 35], \
  [41, 42, 43, 44, 45], \
  [51, 52, 53, 54, 55]])
  
  print(Mat)
  
  snipA = Mat.diagonal()
  snipB = snipA[1:len(snipA)-1]
  print(snipA)
  print(snipB)
  </code></pre>
  
  <p>There are two problems now. First, I cannot modify snipB in any way. I get the error: "output array is read-only". Second, how can I save a modified snipB into the matrix again?</p>
  
  <p>Any help is appreciated.</p>