Last active
August 29, 2015 14:12
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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