Spark 矩阵之外的分布式 BlockMatrix [英] Distributed BlockMatrix out of Spark Matrices
问题描述
如何用矩阵
(相同大小)制作分布式BlockMatrix
?
How to make a distributed
BlockMatrix
out ofMatrices
(of the same size)?
例如,让 A, B 为两个 2 x 2 mllib.linalg.Matrices 如下
For example, let A, B be two 2 by 2 mllib.linalg.Matrices as follows
import org.apache.spark.mllib.linalg.{Matrix, Matrices}
import org.apache.spark.mllib.linalg.distributed.BlockMatrix
val A: Matrix = Matrices.dense(2, 2, Array(1.0, 2.0, 3.0, 4.0))
val B: Matrix = Matrices.dense(2, 2, Array(5.0, 6.0, 7.0, 8.0))
val C = new BlockMatrix(???)
我如何首先从 A、B 制作 RDD[((Int, Int), Matrix)]
,然后从 A、B 制作分布式 BlockMatrix
?
How can I first make an RDD[((Int, Int), Matrix)]
from A, B and second a distributed BlockMatrix
out of A, B?
如果您有任何评论或帮助,我将不胜感激.
I'd appreciate any comment or help in advance.
推荐答案
您可以通过首先创建 RDD[((Int, Int), Matrix)] 来构建
BlockMatrix
代码>
You can construct the BlockMatrix
by first creating the RDD[((Int, Int), Matrix)]
val blocks: RDD[((Int, Int), Matrix)] = sc.parallelize(Seq(((0, 0), A), ((0, 1), B))
然后将其转换为BlockMatrix
.
val blockMatrix: BlockMatrix = new BlockMatrix(blocks, 2, 2)
这会给你一个 BlockMatrix
,它的形式为 [A |B]
.
This will give you a BlockMatrix
, which has the form [A | B]
.
这篇关于Spark 矩阵之外的分布式 BlockMatrix的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!