2016-03-15 91 views
-1

我有一個IndexRowMatrix類型的矩陣。保存IndexedRowMatrix文件在斯卡拉火花

Array(IndexedRow(0,(3,[0,2],[1.0,1.0])), IndexedRow(1,(3,[0,1],[1.0,1.0])), IndexedRow(2,(3,[0],[1.0]))) 

我試圖將其寫入csv文件

indexedRowMatrix.rows.saveAsFile("/user/test/output.csv") 

輸出是在

IndexedRow(0,(3,[0,2],[1.0,1.0])), IndexedRow(1,(3,[0,1],[1.0,1.0])), IndexedRow(2,(3,[0],[1.0])) 

我想在下面的格式

1.0 , 0 , 1.0 
1.0 , 1.0 , 0 
1.0 , 0 , 0 
+0

我建議你看看'map'函數。 –

回答

1

格式找到解決方案

val test = indexedRowMatrix.rows.map(x=> x.vector.toDense) 
test.coalesce(1, true).saveAsTextFile("rdd")