这是我的SparseVector:
mx.foreach(println)
SparseVector((0,1.0), (1,0.0), (2,0.0), (3,0.0), (4,0.0), (5,0.0), (6,0.0), (7,0.0), (8,0.0), (9,0.0), (10,0.0), (11,0.0), (12,0.0))
SparseVector((0,0.0), (1,1.0), (2,0.0), (3,0.0), (4,0.0), (5,0.0), (6,0.0), (7,0.0), (8,0.0), (9,0.0), (10,0.0), (11,0.0), (12,0.0))
SparseVector((0,0.0), (1,0.0), (2,1.0), (3,0.0), (4,0.0), (5,0.0), (6,0.0), (7,0.0), (8,0.0), (9,0.0), (10,0.0), (11,0.0), (12,0.0))
SparseVector((0,0.0), (1,0.0), (2,0.0), (3,1.0), (4,0.0), (5,0.0), (6,0.0), (7,0.0), (8,0.0), (9,0.0), (10,0.0), (11,0.0), (12,0.0))
我想转换为MatrixEntry?
答案 0 :(得分:1)
编辑:鉴于mx
的类型为RDD[SparseVector[Double]]
:
val matrixEntries: RDD[MatrixEntry] = mx.zipWithIndex.flatMap {
case (vector, i) => vector.toArray.zipWithIndex.map {
case (v, j) => MatrixEntry(i, j, v)
}
}