ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 27 Nov 2020 08:54:06 +0100How to find sum of all elements of a matrix in sagemathhttps://ask.sagemath.org/question/54411/how-to-find-sum-of-all-elements-of-a-matrix-in-sagemath/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.Fri, 27 Nov 2020 08:48:10 +0100https://ask.sagemath.org/question/54411/how-to-find-sum-of-all-elements-of-a-matrix-in-sagemath/Answer by FrédéricC for <p>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.</p>
<p>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?</p>
<p>Please help me out.</p>
https://ask.sagemath.org/question/54411/how-to-find-sum-of-all-elements-of-a-matrix-in-sagemath/?answer=54412#post-id-54412Like this
sage: M = matrix(2, 2, [1, 2, 3, 4])
sage: sum(M.coefficients())
10
Fri, 27 Nov 2020 08:54:06 +0100https://ask.sagemath.org/question/54411/how-to-find-sum-of-all-elements-of-a-matrix-in-sagemath/?answer=54412#post-id-54412