title: Replace the diagonal elements of a matrix with sum of other elements in the row in Python
body: <pre><code>import pandas as pd
  import numpy as np
  rates=(pd.read_excel("C:\Anaconda3\RateMatrix.xlsx", sheetname="Pu239Test", skiprows=0)).as_matrix() #read the matrix values from excel spreadsheet, and converts the values to a matrix
  </code></pre>
  
  <p>rates is a 22 x 22 matrix. </p>
  
  <p>I would like to replace the diagonal elements of the Rates matrix with the sum of all other elements in the row. </p>
  
  <p>For example,</p>
  
  <p>rates.item(0,0) = rates.item(0,1)+rates.item(0,2)+rates.item(0,3)+....rates.item(0,21)</p>
  
  <p>rates.item(1,1) = rates.item(1,0)+rates.item(1,2)+rates.item(1,3)+....rates.item(1,21)</p>
  
  <p>.....</p>
  
  <p>rates.item(21,21) = rates.item(21,0)+rates.item(21,2)+rates.item(21,3)+....rates.item(21,20)</p>
  
  <p>I was wondering how I can do that. Thanks a lot in advance.</p>