Created
April 24, 2011 07:03
-
-
Save jColeChanged/939383 to your computer and use it in GitHub Desktop.
My attempt at matrix multiplication in Clojure
This file contains hidden or 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 C_yx [m1 m2 y x num-cols num-rows] | |
(reduce + | |
(map * | |
(map #(nth (nth m1 y) %1) (range num-cols)) | |
(map #(nth (nth m2 %1) x) (range num-rows))))) | |
(defn multiply [m1 m2] | |
(let [num-rows (count m1) num-cols (count (first m1))] | |
(for [y (range num-rows)] | |
(for [x (range num-cols)] | |
(C_yx m1 m2 y x num-rows num-cols))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment