Skip to content

Instantly share code, notes, and snippets.

@tnoda
Last active August 29, 2015 14:12
Show Gist options
  • Save tnoda/f0054560c899680eaf1c to your computer and use it in GitHub Desktop.
Save tnoda/f0054560c899680eaf1c to your computer and use it in GitHub Desktop.
The id-mat function in page 17 of the book, "Clojure for Machine Learning" by Akhil Wali, does not work.
(defn id-mat
"Creates an identity matrix of n x n size"
[n]
(let [init (square-mat n 0 :implementation :clatrix)
identity-f (fn [i j n]
(if (= i j) 1 n))]
(cl/map-indexed identity-f init)))
;; clj-ml1.matrix-basics> (id-mat 5)
;; A 5x5 matrix
;; -------------
;; 1.00e+00 0.00e+00 0.00e+00 0.00e+00 0.00e+00
;; 0.00e+00 1.00e+00 0.00e+00 0.00e+00 0.00e+00
;; 0.00e+00 0.00e+00 1.00e+00 0.00e+00 0.00e+00
;; 0.00e+00 0.00e+00 0.00e+00 1.00e+00 0.00e+00
;; 0.00e+00 0.00e+00 0.00e+00 0.00e+00 1.00e+00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment