Ask Your Question
0

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

asked 2020-11-27 08:48:10 +0100

Captcha gravatar image

updated 2020-11-27 08:49:12 +0100

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
0

answered 2020-11-27 08:54:06 +0100

FrédéricC gravatar image

Like this

sage: M = matrix(2, 2, [1, 2, 3, 4])                                                   
sage: sum(M.coefficients())                                                     
10
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

Stats

Asked: 2020-11-27 08:48:10 +0100

Seen: 731 times

Last updated: Nov 27 '20