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.Source
to read in tab delimited data from file.Some sample data:
One of the
DenseMatrix
constructors 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
res0
andres1
can be used to create a newDenseMatrix
.