pyspark mllib IndexedRowMatrix 类型如何通过索引获取项目

pyspark mllib IndexedRowMatrix type how to get item by indices

是否可以通过提供坐标从mllib indexedRowMatrix类型中获取矩阵内容?例如

rows = sc.parallelize([IndexedRow(0, [1, 2, 3]),IndexedRow(1, [4, 5, 6]),IndexedRow(2, [7, 8, 9]),IndexedRow(3, [10, 11, 12])])
mat = IndexedRowMatrix(rows)

如果我给出坐标(0,1),我应该从mat

得到2

Spark 矩阵(和一般的分布式容器)不支持随机访问。可以 filter:

mat.rows.filter(lambda row: row.index == 0).first().vector[1]

但是这个操作在行数方面是线性的。