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
Comments top
No comments for matrix. Log in to add a comment.