如何在pyspark中显示块矩阵乘法的结果?

cs7cruho  于 2021-07-12  发布在  Spark
关注(0)|答案(1)|浏览(560)

这听起来像是一个简单的问题,但我不知道如何将pyspark blockmatrix的内容显示到控制台。我应该调用什么方法来实际查看结果?

t2a7ltrp

t2a7ltrp1#

你可以打电话 toLocalMatrix() . 我使用spark mllib python api文档中的示例矩阵来说明:

  1. mat = mat1.toLocalMatrix()
  2. # which returns a DenseMatrix
  3. # DenseMatrix(6, 2, [1.0, 2.0, 3.0, 7.0, 8.0, 9.0, 4.0, 5.0, 6.0, 10.0, 11.0, 12.0], 0)
  4. # and could be further converted to a numpy array using `.toArray()`:
  5. np_mat = mat.toArray()
  6. # array([[ 1., 4.],
  7. # [ 2., 5.],
  8. # [ 3., 6.],
  9. # [ 7., 10.],
  10. # [ 8., 11.],
  11. # [ 9., 12.]])
展开查看全部

相关问题