當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python pyspark BlockMatrix.toLocalMatrix用法及代碼示例

本文簡要介紹 pyspark.mllib.linalg.distributed.BlockMatrix.toLocalMatrix 的用法。

用法:

toLocalMatrix()

將驅動程序上的分布式矩陣收集為 DenseMatrix。

例子

>>> blocks = sc.parallelize([((0, 0), Matrices.dense(3, 2, [1, 2, 3, 4, 5, 6])),
...                          ((1, 0), Matrices.dense(3, 2, [7, 8, 9, 10, 11, 12]))])
>>> mat = BlockMatrix(blocks, 3, 2).toLocalMatrix()
>>> # This BlockMatrix will have 6 effective rows, due to
>>> # having two sub-matrix blocks stacked, each with 3 rows.
>>> # The ensuing DenseMatrix will also have 6 rows.
>>> print(mat.numRows)
6
>>> # This BlockMatrix will have 2 effective columns, due to
>>> # having two sub-matrix blocks stacked, each with 2
>>> # columns. The ensuing DenseMatrix will also have 2 columns.
>>> print(mat.numCols)
2

相關用法


注:本文由純淨天空篩選整理自spark.apache.org大神的英文原創作品 pyspark.mllib.linalg.distributed.BlockMatrix.toLocalMatrix。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。