Ask Your Question

How to find sum of all elements of a matrix in sagemath

asked 2020-11-27 01:48:10 -0600

Captcha gravatar image

updated 2020-11-27 01:49:12 -0600

I have a matrix of order n say M. If I do sum(M) I would get the a vector in which all the entries would give me the sum of elements of each row of M.

How can I find the sum of all elements of M? Does there exist any command which can return the sum of all elements of a matrix?

Please help me out.

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

answered 2020-11-27 01:54:06 -0600

FrédéricC gravatar image

Like this

sage: M = matrix(2, 2, [1, 2, 3, 4])                                                   
sage: sum(M.coefficients())                                                     
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2020-11-27 01:48:10 -0600

Seen: 42 times

Last updated: Nov 27 '20