scala - How to change RowMatrix into Array in Spark or export it as a CSV? -


i've got code in scala:

val mat: coordinatematrix = new coordinatematrix(data) val rowmatrix: rowmatrix = mat.torowmatrix()  val svd: singularvaluedecomposition[rowmatrix, matrix] = rowmatrix.computesvd(100, computeu = true)  val u: rowmatrix = svd.u // u factor rowmatrix. val s: vector = svd.s // singular values stored in local dense vector. val v: matrix = svd.v // v factor local dense matrix.  val uarray: array[double] = u.toarray // doesn't work, because there not toarray function in rowmatrix type val sarray: array[double] = s.toarray // works val varray: array[double] = v.toarray // works 

how can change u uarray or similar type, printed out csv file?

that's basic operation, here have considering u rowmatrix following :

val u = svd.u 

rows() rowmatrix method allows rdd rowmatrix row.

you'll need apply rows on rowmatrix , map rdd[vector] create array concatenate string creating rdd[string].

val rdd = u.rows.map( x => x.toarray.mkstring(",")) 

all you'll have save rdd :

rdd.saveastextfile(path) 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -