core.matrix question: how to compute sum of elements in an array or matrix?

61 views
Skip to first unread message

Joachim De Beule

unread,
Nov 28, 2016, 3:43:39 PM11/28/16
to Numerical Clojure
I can't seem to find any specialised way in the clojure.core.matrix api docs for getting the sum of all elements in an array or matrix, or for summing all rows etc. 

How should I go about this in core.matrix?

Thanks,
Joachim.


Joachim De Beule

unread,
Nov 28, 2016, 4:55:18 PM11/28/16
to Numerical Clojure
never mind, found it: esum, and then 

And this for a matrix m I guess

(reduce + (map esum (rows ma)))

Mike Anderson

unread,
Dec 6, 2016, 11:22:09 PM12/6/16
to Numerical Clojure
You should be able to do (esum my-array) on the whole array.

This should work for arrays of any shape.
Reply all
Reply to author
Forward
0 new messages