1.2.3-SNAPSHOT Arrow_down_16x16

matrix-map

incanter.core

  • (matrix-map f m)
  • (matrix-map f m & ms)
Like clojure.core/map, but will work on matrices of any dimension:
1 x 1 (like e.g. a Double), 1 x n, n x 1, and n x m

Examples:
(use '(incanter core))
(def mat (matrix (range 9) 3))
(matrix-map #(mod % 2) mat)
(matrix-map #(mod % 2) (first mat))
(matrix-map #(mod % 2) ($ 1 0 mat))
(matrix-map #(mod % 2) [1 2 3 4])
(matrix-map #(mod % 2) 9)

0 Examples top

Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source incanter/core.clj:1834 top

(defn matrix-map
 "Like clojure.core/map, but will work on matrices of any dimension:
 1 x 1 (like e.g. a Double), 1 x n, n x 1, and n x m

  Examples:
    (use '(incanter core))
    (def mat (matrix (range 9) 3))
    (matrix-map #(mod % 2) mat)
    (matrix-map #(mod % 2) (first mat))
    (matrix-map #(mod % 2) ($ 1 0 mat))
    (matrix-map #(mod % 2) [1 2 3 4])
    (matrix-map #(mod % 2) 9)

"
 ([f m]
    (if (sequential? m)
      (if (sequential? (first m))
        (map (fn [& a] (apply map f a)) m)
        (map f m))
      (f m)))
 ([f m & ms]
    (if (sequential? m)
      (if (sequential? (first m))
        (apply map (fn [& a] (apply map f a)) m ms)
        (apply map f m ms))
      (apply f m ms))))
Vars in incanter.core/matrix-map: apply defn first fn map sequential?
Used in 0 other vars

Comments top

No comments for matrix-map. Log in to add a comment.