Reputation: 354
I have a sparse vector:
(453,[0,4,11,16,39,56,109],[1.0,1.0,1.0,1.0,1.0,1.0,1.0])
and I need to convert it into dense vector (should be able to see all 453 values).
How to do that in Scala Spark?
Upvotes: 6
Views: 10169
Reputation: 354
It can be done by using SparseVector's toDense
method:
val sv = Vectors.sparse(5, Array(0, 3), Array(1.5, -1.5))
sv.toDense
// res0: org.apache.spark.mllib.linalg.DenseVector = [1.5,0.0,0.0,-1.5,0.0]
Upvotes: 11