Reputation: 61
this is my 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))
i want convert to MatrixEntry?
Upvotes: 1
Views: 118
Reputation: 37832
EDIT: given that mx
's type is RDD[SparseVector[Double]]
:
val matrixEntries: RDD[MatrixEntry] = mx.zipWithIndex.flatMap {
case (vector, i) => vector.toArray.zipWithIndex.map {
case (v, j) => MatrixEntry(i, j, v)
}
}
Upvotes: 1