How to create SparseVector
and dense Vector representations
if the DenseVector
is:
denseV = np.array([0., 3., 0., 4.])
What will be the Sparse Vector representation ?
How to create SparseVector
and dense Vector representations
if the DenseVector
is:
denseV = np.array([0., 3., 0., 4.])
What will be the Sparse Vector representation ?
Sparse vectors are when you have a lot of values in the vector as zero. While a dense vector is when most of the values in the vector are non zero.
If you have to create a sparse vector from the dense vector you specified, use the following syntax:
Unless I have thoroughly misunderstood your doubt, the MLlib data type documentation illustrates this quite clearly:
Where the second argument of
Vectors.sparse
is an array of the indices, and the third argument is the array of the actual values in those indices.