1

I have this solution which works but I wonder if there's a clever way to do it, avoiding the explicit for loop and the toString.toDouble conversion

import scala.collection.mutable.ArrayBuffer

val rows: Array[Row] = df2.collect()
//rows: Array[org.apache.spark.sql.Row] = Array([-1.35980713367,...

var e = ArrayBuffer[Array[Double]]()

for(row <- rows){
  val x = row.toSeq.toArray
  val y = x.map(_.toString.toDouble)
  e += y
}
val dm = DenseMatrix(e.toArray:_*)
MLeiria
  • 633
  • 1
  • 9
  • 22

0 Answers0