Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a Breeze DenseMatrix using an existing List of Lists in Scala

I've a

List[List[Int]] = List(List(1, 2, 3, 0, 0, 0, 0, 0, 0), List(0, 0, 0, 1, 2, 3, 0, 0, 0), List(0, 0, 0, 0, 0, 0, 1, 2, 3))

and I want to create a Matrix/DenseMatrix with 3 rows and 9 columns so that I can perform some Linear Algebra operations on it.

like image 709
Soumya Simanta Avatar asked Dec 21 '25 23:12

Soumya Simanta


1 Answers

There's not great syntax for this yet. I actually ran into it today, so I'll probably add better support for it soon. In the meantime, DenseMatrix(array1, array2, array3) works. So:

val listOfLists : List[List[Int]] = ???

DenseMatrix(listOfLists.map(_.toArray):_*)

Not the prettiest, but I'll add better support if you open a ticket.

like image 75
dlwh Avatar answered Dec 23 '25 12:12

dlwh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!