且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在PySpark中建立稀疏矩阵?

更新时间:2021-10-05 03:51:57

喜欢:

from pyspark.mllib.linalg.distributed import CoordinateMatrix, MatrixEntry

# Create an RDD of (row, col, value) triples
coordinates = sc.parallelize([(1, 2, 1), (1, 3, 5)])
matrix = CoordinateMatrix(coordinates.map(lambda coords: MatrixEntry(*coords)))