0

Say I have a dataframe resulted from a sequence of transformations. It looks like the following:

id matrixRow
0  [1,2,3]
1  [4,5,6]
2  [7,8,9]

each row actually corresponds to a row of a matrix. How can I convert the matrixRow column of the dataframe to RowMatrix?

6
  • 1
    What language are using? Commented Sep 1, 2017 at 17:21
  • @Psidom I'm using scala Commented Sep 1, 2017 at 17:50
  • When you say matrix, do you mean an array of arrays or a scale-breeze matrix? Commented Sep 1, 2017 at 18:41
  • No, it refers to a matrix in the context of algebra. Commented Sep 1, 2017 at 19:10
  • OK. So what data structure are you trying to implement the algebra matrix in? Commented Sep 1, 2017 at 19:15

1 Answer 1

2

After numerous tries, here's one solution:

val rdd = df.rdd.map(
           row => Vectors.dense(row.getAs[Seq[Double]](1).toArray)//get the second column value as Seq[Double], then as Array, then cast to Vector
          )
val row = new RowMatrix(rdd)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.