0

I have data for N rows xM rows DenseVector[DenseVector[Double]] (or DenseMatrix[DenseMatrix[Double]]) and want to convert this object into an NxM's DenseMatrix object

DenseVector(DenseVector(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0), DenseVector(11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0), DenseVector(11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0), DenseVector(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0))

converted single DenseMatrix object

 1.0,  2.0,  3.0,  4.0,  5.0,  6.0,  7.0,  8.0
11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0
11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0
 1.0,  2.0,  3.0,  4.0,  5.0,  6.0,  7.0,  8.0

Here is the test code, It can't executed.

object BreezeTest extends App {
    val mx = Array(Array(Array(1.0,2.0,3.0,4.0),Array(5.0,6.0,7.0,8.0)),Array(Array(11.0,12.0,13.0,14.0),Array(15.0,16.0,17.0,18.0)))

    val my = Array(Array(0,1),Array(1,0))
    val myND =DenseMatrix(my:_*)
    val newND = myND.map(s=>DenseVector(mx(s).flatten)).flatten()   // here is 4d array,It's difficult process,so try flat to 2d matrix 
    println(newND)
    println(DenseMatrix.vertcat(newND:_*)

}
Nosrep
  • 521
  • 7
  • 21
lemanli
  • 119
  • 1
  • 1
  • 7
  • What is `DenseVector`? What is `DenseMatrix`? – Tomer Shetah Dec 20 '20 at 09:53
  • What is the initial data representation. Do you have your data as Arrays... or other Collection?, because you don´t need to build DenseVectors to build a DenseMatrix, you can build directly the Matrix – Emiliano Martinez Dec 20 '20 at 18:56
  • Yes, thank you for your answer, it's possible to create DenseMatrix directly, but it won't solve my problem. Because I have a few matrices that do some transformations between each other and end up in this situation, I want to see how I can do sth. resolve them. – lemanli Dec 21 '20 at 01:00

0 Answers0