I want to read a tab-delimited text file into a Breeze DenseMatrix. I see in the ScalaDoc that this should be possible and there are a whole set of I/O classes, but I can't find any examples and it's hard to digest the ScalaDoc.
Can someone provide a simple read/write example?
You can use
scala.io.Sourceto read in tab delimited data from file.Some sample data:
One of the
DenseMatrixconstructors has this formnew DenseMatrix(rows: Int, data: Array[V], offset: Int = 0)so I'll use that.Get the number of rows:
Then get the data as an
Array[Int]:Then
res0andres1can be used to create a newDenseMatrix.