Skip to content

Instantly share code, notes, and snippets.

@erasmas
Last active August 29, 2015 14:07
Show Gist options
  • Save erasmas/0d946ca76a17fb309bee to your computer and use it in GitHub Desktop.
Save erasmas/0d946ca76a17fb309bee to your computer and use it in GitHub Desktop.
Matrix trace using map-indexed from clatrix library.
(require '[clatrix.core :as cl])
(import '[clatrix.core Matrix])
(defn matrix-trace
[^Matrix m]
(->> m
(cl/map-indexed (fn [i j v] (if (= i j) v 0)))
(mapv #(reduce + %))
(reduce +)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment