matrix transposition in clojure

前端 未结 2 1106
野的像风
野的像风 2020-11-27 20:06

In clojure a possible representation of a matrix is a vector of vectors, i.e. [[1 2] [3 4]]. A possible implementation of transposing a matrix would be:

相关标签:
2条回答
  • 2020-11-27 20:40

    The usual solution is

    (defn transpose [m]
      (apply mapv vector m))
    
    0 讨论(0)
  • 2020-11-27 20:41

    As of 2014, I would recommend using core.matrix for any numerical work in Clojure.

    Among other things, this provides implementations of all the most common matrix operations:

    (use 'clojure.core.matrix)
    
    (transpose [[1 2] [3 4]])
    => [[1 3] [2 4]]
    
    0 讨论(0)
提交回复
热议问题