这听起来像是一个简单的问题,但我不知道如何将pyspark blockmatrix的内容显示到控制台。我应该调用什么方法来实际查看结果?
t2a7ltrp1#
你可以打电话 toLocalMatrix() . 我使用spark mllib python api文档中的示例矩阵来说明:
toLocalMatrix()
mat = mat1.toLocalMatrix()# which returns a DenseMatrix# 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)# and could be further converted to a numpy array using `.toArray()`:np_mat = mat.toArray()# array([[ 1., 4.],# [ 2., 5.],# [ 3., 6.],# [ 7., 10.],# [ 8., 11.],# [ 9., 12.]])
mat = mat1.toLocalMatrix()
# which returns a DenseMatrix
# 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)
# and could be further converted to a numpy array using `.toArray()`:
np_mat = mat.toArray()
# array([[ 1., 4.],
# [ 2., 5.],
# [ 3., 6.],
# [ 7., 10.],
# [ 8., 11.],
# [ 9., 12.]])
1条答案
按热度按时间t2a7ltrp1#
你可以打电话
toLocalMatrix()
. 我使用spark mllib python api文档中的示例矩阵来说明: