0
I持って一つのキー/値ペアRDD疎行列にRDD pysparkを変換する方法
{(("a", "b"), 1), (("a", "c"), 3), (("c", "d"), 5)}
私は疎行列を得ることができる方法:
0 1 3 0
1 0 0 0
3 0 0 5
0 0 5 0
すなわち
from pyspark.mllib.linalg import Matrices
Matrices.sparse(4, 4, [0, 2, 3, 5, 6], [1, 2, 0, 0, 3, 2], [1, 3, 1, 3, 5, 5])
か
import numpy as np
from scipy.sparse import csc_matrix
data = [1, 3, 1, 3, 5, 5]
indices = [1, 2, 0, 0, 3, 2]
indptr = [0, 2, 3, 5, 6]
csc_matrix((data, indices, indptr), shape=(4, 4), dtype=np.float)