1

I've got a general matrix K that I would like to divide it's row's by the row sums of the matrix. I could get this going by doing

SumK=Total[K,{1}];
P=Flatten[Table[{Part[K, i]/Part[SumK, i]}, {i, 1, 3}], {1, 2}]

Is there a better way of doing this? I'm not sure how much faster I can make it, but you guys always seem to surprise me...

DaveNine
  • 183
  • 5
  • Could you link where the duplicate to this question is? I could find one on columns, but I felt the nature of adding rows in mathematica was a bit different. – DaveNine Aug 27 '13 at 23:01
  • @DavidSacco Operations on columns and rows are not much different, as they're just a transpose away. In your case, you can use either Vitaliy's or my answer in the linked question by removing both transposes (i.e. Normalize[#, Total]& /@ mat is an answer to your problem). In addition, I also had #/Tr@#& /@ mat as an answer (now deleted). I've also edited my answer there to include solutions for row normalizations. – rm -rf Aug 27 '13 at 23:04
  • thanks, I understand the difference now. – DaveNine Aug 28 '13 at 04:55

0 Answers0