我正在考虑Clojure / Incanter作为R的替代方案,只是想知道clojure / incanter是否有能力执行以下操作:
发布于 2013-02-05 02:08:41
您可能对core.matrix感兴趣--这是一个将多维数组和数值计算功能引入Clojure的项目。仍然处于非常活跃的开发阶段,但已经可以使用了。
功能:
[[1 2] [3 4]]可以自动作为2x2矩阵使用。参见这里的一些示例代码:
;; a matrix can be defined using a nested vector
(def a (matrix [[2 0] [0 2]]))
;; core.matrix.operators overloads operators to work on matrices
(* a a)
;; a wide range of mathematical functions are defined for matrices
(sqrt a)
;; you can get rows and columns of matrices individually
(get-row a 0)
;; Java double arrays can be used as vectors
(* a (double-array [1 2]))
;; you can modify double arrays in place - they are examples of mutable vectors
(let [a (double-array [1 4 9])]
(sqrt! a) ;; "!" signifies an in-place operator
(seq a))
;; you can coerce matrices between different formats
(coerce [] (double-array [1 2 3]))
;; scalars can be used in many places that you can use a matrix
(* [1 2 3] 2)
;; operations on scalars alone behave as you would expect
(* 1 2 3 4 5)
;; you can do various functional programming tricks with matrices too
(emap inc [[1 2] [3 4]])core.matrix已经被Rich批准为一个官方的Clojure contrib库,而且很可能Incanter将来会转而使用core.matrix。
core.matrix中没有直接包含SQL表支持,但它只是将结果集从clojure.java.jdbc转换为core.matrix数组的一行代码。下面这样的东西应该能起作用:
(coerce [] (map vals resultset))然后,您可以使用core.matrix来转换和处理它,不管您喜欢什么。
https://stackoverflow.com/questions/14698114
复制相似问题