How to draw WrappedArray [WrappedArray [Float]] in Array [Array [Float]] in sparks (scala)

Im using Spark 2.0. I have a column in my frame containing WrappedArrayWrappedArrays of Float.

Example line:

[[1.0 2.0 2.0][6.0 5.0 2.0][4.0 2.0 3.0]]

I am trying to convert this column to . Array[Array[Float]]

I have tried so far the following:

dataframe.select("mycolumn").rdd.map(r => r.asInstanceOf[Array[Array[Float]]])

but I get the following error:

Caused by: java.lang.ClassCastException:
 org.apache.spark.sql.catalyst.expressions.GenericRowWithSchema cannot be cast to [[F

Any idea would be greatly appreciated. Thanks

+4
source share
2 answers

Try the following:

  val wawa: WrappedArray[WrappedArray[Float]] = null 
  val res: Array[Array[Float]] = wawa.map(inner => inner.array).toArray

It compiles for me

+3
source

Following @ sami-badawi's answer, I am posting a response for those I need, starting with a data frame.

dataframe.select("mycolumn").rdd.map
(row => row.get(0).asInstanceOf[WrappedArray[WrappedArray[Float]]].array.map(x=>x.toArray))
+1
source

Source: https://habr.com/ru/post/1668063/


All Articles