Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defn abstractOperation [operation]
- (fn [a b] (mapv operation a b)))
- (defn modifyLines [op neural m] (mapv (fn [curLine] (op curLine neural)) m))
- ;; Vector operations
- (def v+ (abstractOperation +))
- (def v- (abstractOperation -))
- (def v* (abstractOperation *))
- (defn v*s [v s] (mapv (fn [xi] (* xi s)) v))
- (defn scalar [a b] (reduce + (v* a b)))
- ;; Matrix operations
- (def m- (abstractOperation v-))
- (def m* (abstractOperation v*))
- (def m+ (abstractOperation v+))
- (defn m*s [m s] (modifyLines v*s s m))
- (defn m*v [m v] (modifyLines scalar v m))
- (defn transpose [m]
- (apply mapv vector m))
- (print (scalar [1 2 3] [4 5 6]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement