You can use scala.io.Source
to read in tab delimited data from file.
Some sample data:
0 1 2 3 4 5
6 7 8 9 10 11
One of the DenseMatrix
constructors has this form new DenseMatrix(rows: Int, data: Array[V], offset: Int = 0)
so I'll use that.
Get the number of rows:
scala> scala.io.Source.fromFile("TabDelimited.txt").getLines.size
res 0:Int = 2
Then get the data as an Array[Int]
:
scala> scala.io.Source.fromFile("TabDelimited.txt").getLines.toArray.flatMap(_.split("\t")).map(_.toInt)
res1: Array[Int] = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
Then res0
and res1
can be used to create a new DenseMatrix
.