1.2.3-SNAPSHOT permalink Arrow_down_16x16

matrix

incanter.core

  • (matrix data)
  • (matrix data ncol)
  • (matrix init-val rows cols)

Returns an instance of an incanter.Matrix, which is an extension of
cern.colt.matrix.tdouble.impl.DenseColDoubleMatrix2D that implements the Clojure
interface clojure.lang.ISeq. Therefore Clojure sequence operations can
be applied to matrices. A matrix consists of a sequence of rows, where
each row is a one-dimensional row matrix. One-dimensional matrices are
in turn, sequences of numbers. Equivalent to R's matrix function.

Examples:
(def A (matrix [[1 2 3] [4 5 6] [7 8 9]])) ; produces a 3x3 matrix
(def A2 (matrix [1 2 3 4 5 6 7 8 9] 3)) ; produces the same 3x3 matrix
(def B (matrix [1 2 3 4 5 6 7 8 9])) ; produces a 9x1 column vector

(first A) ; produces a row matrix [1 2 3]
(rest A) ; produces a sub matrix [[4 5 6] [7 8 9]]
(first (first A)) ; produces 1.0
(rest (first A)) ; produces a row matrix [2 3]

; since (plus row1 row2) adds the two rows element-by-element
(reduce plus A) ; produces the sums of the columns

; and since (sum row1) sums the elements of the row
(map sum A) ; produces the sums of the rows

; you can filter the rows using Clojure's filter function
(filter #(> (nth % 1) 4) A) ; returns the rows where the second column is greater than 4.

References:
http://incanter.org/docs/parallelcolt/api/cern/colt/matrix/tdouble/DoubleMatrix2D.html

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:61 top

(defn matrix
"
  Returns an instance of an incanter.Matrix, which is an extension of
  cern.colt.matrix.tdouble.impl.DenseColDoubleMatrix2D that implements the Clojure
  interface clojure.lang.ISeq. Therefore Clojure sequence operations can
  be applied to matrices. A matrix consists of a sequence of rows, where
  each row is a one-dimensional row matrix. One-dimensional matrices are
  in turn, sequences of numbers. Equivalent to R's matrix function.

  Examples:
    (def A (matrix [[1 2 3] [4 5 6] [7 8 9]])) ; produces a 3x3 matrix
    (def A2 (matrix [1 2 3 4 5 6 7 8 9] 3)) ; produces the same 3x3 matrix
    (def B (matrix [1 2 3 4 5 6 7 8 9])) ; produces a 9x1 column vector

    (first A) ; produces a row matrix [1 2 3]
    (rest A) ; produces a sub matrix [[4 5 6] [7 8 9]]
    (first (first A)) ; produces 1.0
    (rest (first A)) ; produces a row matrix [2 3]

    ; since (plus row1 row2) adds the two rows element-by-element
    (reduce plus A) ; produces the sums of the columns

    ; and since (sum row1) sums the elements of the row
    (map sum A) ; produces the sums of the rows

    ; you can filter the rows using Clojure's filter function
    (filter #(> (nth % 1) 4) A) ; returns the rows where the second column is greater than 4.

  References:
    http://incanter.org/docs/parallelcolt/api/cern/colt/matrix/tdouble/DoubleMatrix2D.html

"
  ([data]
   (make-matrix data))

  ([data ^Integer ncol]
   (make-matrix data ncol))

  ([init-val ^Integer rows ^Integer cols]
   (make-matrix init-val rows cols)))
Vars in incanter.core/matrix: defn
Used in 0 other vars

Comments top

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