Skip to content

Instantly share code, notes, and snippets.

@manvillej
Last active October 23, 2018 13:10
Show Gist options
  • Save manvillej/1478d72656c06feeeabd0e2fad75b3a4 to your computer and use it in GitHub Desktop.
Save manvillej/1478d72656c06feeeabd0e2fad75b3a4 to your computer and use it in GitHub Desktop.
summing a row in a matrix.
>>> matrix
matrix([[ 2., 0., 1., 0., 0., 0., 1., 0., 0., 1.],
[ 0., 2., 0., 1., 0., 1., 0., 0., 0., 0.],
[ 1., 0., 2., 0., 0., 0., 0., 0., 1., 1.],
[ 0., 1., 0., 3., 0., 1., 0., 1., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 1., 0., 1., 0., 3., 0., 1., 0., 0.],
[ 1., 0., 0., 0., 0., 0., 2., 0., 1., 1.],
[ 0., 0., 0., 1., 0., 1., 0., 2., 0., 0.],
[ 0., 0., 1., 0., 0., 0., 1., 0., 2., 1.],
[ 1., 0., 1., 0., 0., 0., 1., 0., 1., 2.]])
>>> np.sum(matrix[0]) # 0 would be the starting position
5.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment