Scala Spark - convert DenseVector with nulls to SparseVector

I have quite big vector of around 20k Doubles most of which are null. Is it possible to convert it to the SparseVector and how?

Upvotes: 0

Views: 99

Answers (1)

user8949017
user8949017

Reputation: 21

org.apache.spark.ml.linalg.Vector provides toSparse and toDense methods which can be used to change the representation.

However it shouldn't possible to have Vector (or any other collection like object) of scala.Double containing nulls in the first place.

Upvotes: 2

Related Questions