First time here? Check out the FAQ!

Ask Your Question
0

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

asked 4 years ago

Captcha gravatar image

updated 4 years ago

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.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
0

answered 4 years ago

FrédéricC gravatar image

Like this

sage: M = matrix(2, 2, [1, 2, 3, 4])                                                   
sage: sum(M.coefficients())                                                     
10
Preview: (hide)
link

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: 4 years ago

Seen: 892 times

Last updated: Nov 27 '20