代码之家  ›  专栏  ›  技术社区  ›  cpd1

处理坐标矩阵时矩阵中心不可iterable。。。pyspark MLlib

  •  1
  • cpd1  · 技术社区  · 7 年前

    test = test.entries.map(lambda (i, j, v): (j, (i, v)))
    

    Scala中的等效项似乎有效,但在pyspark中失败。行执行时出现的错误。。。

    'MatrixEntry' object is not iterable
    

    >>> test = test_coord.entries
    >>> test.first()
    >>> MatrixEntry(0, 0, 7.0)
    

    有人知道会发生什么吗?

    1 回复  |  直到 7 年前
        1
  •  2
  •   akuiper    7 年前

    test 是一个 协调矩阵

    test.entries.map(lambda e: (e.j, (e.i, e.value)))
    

    map(lambda (x, y, z): ) 在这种情况下是行不通的,即使这似乎不是失败的原因。


    实例 :

    test = CoordinateMatrix(sc.parallelize([(1,2,3), (4,5,6)]))
    test.entries.collect()
    # [MatrixEntry(1, 2, 3.0), MatrixEntry(4, 5, 6.0)]
    test.entries.map(lambda e: (e.j, (e.i, e.value))).collect()
    # [(2L, (1L, 3.0)), (5L, (4L, 6.0))]