火花矩阵之外的分布式BlockMatrix [英] Distributed BlockMatrix out of Spark Matrices
本文介绍了火花矩阵之外的分布式BlockMatrix的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何用
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)]
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]
.
这篇关于火花矩阵之外的分布式BlockMatrix的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文