稀疏向量vs密集向量 [英] Sparse Vector vs Dense Vector
本文介绍了稀疏向量vs密集向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何创建SparseVector
和密集的Vector表示形式
How to create SparseVector
and dense Vector representations
如果DenseVector
是:
denseV = np.array([0., 3., 0., 4.])
稀疏向量表示将是什么?
What will be the Sparse Vector representation ?
推荐答案
Unless I have thoroughly misunderstood your doubt, the MLlib data type documentation illustrates this quite clearly:
import org.apache.spark.mllib.linalg.Vector;
import org.apache.spark.mllib.linalg.Vectors;
// Create a dense vector (1.0, 0.0, 3.0).
Vector dv = Vectors.dense(1.0, 0.0, 3.0);
// Create a sparse vector (1.0, 0.0, 3.0) by specifying its indices and values corresponding to nonzero entries.
Vector sv = Vectors.sparse(3, new int[] {0, 2}, new double[] {1.0, 3.0});
Vectors.sparse
的第二个参数是索引的数组,而第三个参数是这些索引中的实际值的数组.
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.
这篇关于稀疏向量vs密集向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文