在下面的代码中,我在进行SVD后获得了密集的Matrix V.我想要的是
val data = Array( Vectors.sparse(5, Seq((1, 1.0), (3, 7.0))), Vectors.dense(2.0, 0.0, 3.0, 4.0, 5.0), Vectors.dense(4.0, 0.0, 0.0, 6.0, 7.0)) val dataRDD = sc.parallelize(data) val mat: RowMatrix = new RowMatrix(dataRDD) // Compute the top 4 singular values and corresponding singular vectors. val svd: SingularValueDecomposition[RowMatrix, Matrix] = mat.computeSVD(4, computeU = true) val U: RowMatrix = svd.U // The U factor is a RowMatrix. val s: Vector = svd.s // The singular values are stored in a local dense vector. val V: Matrix = svd.V // The V factor is a local dense matrix.
请告知一种有效的方法来做同样的事情。我一直在考虑将Matrix V转换为索引行矩阵,但是当我在V上使用行迭代器时,如何跟踪行的索引?有没有更好的方法呢?