Ask Your Question

Revision history [back]

For summing rows:

sage: sum(M)
(0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1)

For the columns:

sage: sum(M.columns())
(0, 1, 0, 1, 0, 0, 1, 0)

or

sage: sum(M.T)
(0, 1, 0, 1, 0, 0, 1, 0)

For summing rows:

sage: M = random_matrix(ZZ,3,5)
sage: M
[ -2   1 -10  -1  -1]
[ -2   1  -1   1  -1]
[ -3   5  -2   1   2]

sage: sum(M)
(0, (-7, 7, -13, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1)
0)

For the columns:

sage: sum(M.columns())
(0, 1, 0, 1, 0, 0, 1, 0)
(-13, -2, 3)

or

sage: sum(M.T)
(0, 1, 0, 1, 0, 0, 1, 0)
(-13, -2, 3)