Question

Consider a function that outputs an Incanter matrix.

Here is an example matrix containing output from the function:

A 6x4 matrix 
-4.77e-01 8.45e-01  1.39e-01 -9.83e-18
 8.55e-01 2.49e-01  1.33e-01  2.57e-17
-2.94e-03 6.60e-03 -9.63e-01  1.16e-16
...
 6.64e-09  2.55e-08  1.16e-07 -1.11e-16
-1.44e-01 -3.33e-01  1.32e-01 -7.07e-01
-1.44e-01 -3.33e-01  1.32e-01  7.07e-01

I'd like to continue analyzing the rows of the matrix, which represent points. The function that I want to feed the Incanter matrix to takes nested vectors as inputs.

So the function would need the above data in the form

[[-4.77e-01 8.45e-01  1.39e-01 -9.83e-18]  [8.55e-01 2.49e-01  1.33e-01  2.57e-17]
 [-2.94e-03 6.60e-03 -9.63e-01  1.16e-16]  [6.64e-09  2.55e-08  1.16e-07 -1.11e-16]
 [-1.44e-01 -3.33e-01  1.32e-01 -7.07e-01] [-1.44e-01 -3.33e-01  1.32e-01  7.07e-01]]

It is the transformation from the Incanter matrix representation to the nested vector structure that I am unsure how to perform. Is there a simple way to convert the data's representation?

Was it helpful?

Solution

You can do it with build-in to-vect function:

(to-vect m)

or with build-in to-list function:

(to-list m)

Both functions will produce vector-of-vectors when given a matrix:

=> (def m (matrix [[1 2] [3 4]]))
 A 2x2 matrix
 -------------
 1.00e+00  2.00e+00 
 3.00e+00  4.00e+00 

=> (to-vect m)
[[1.0 2.0] [3.0 4.0]]
=> (to-list m)
[[1.0 2.0] [3.0 4.0]]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top