I am new to clojure and functional programming and I need to convert Java class org.apache.commons.math3.linear.OpenMapRealMatrix
to clojure vector.
How Is it possible to do that?
If you want to keep two dimensional matrix, just below code is fine :)
(mapv #(vec (.getRow matrix %))
(range (.getRowDimension matrix)))
It's hard to give a direct answer because converting from two dimensional matrix to a one dimensional vector involves . 。 If we choose left to right top to bottom one approach would look something like this:
(->> (for [r (range 0 (.getRowDimension matrix))]
(vec (.getRow matrix r)))
flatten
vec) ;; this step is optional
Or if you only have one row then you could just call (vec (.getRow matrix 0))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.