【问题标题】:difference between 2 scipy sparse csr matrices2个scipy稀疏csr矩阵之间的区别
【发布时间】:2017-10-18 04:39:38
【问题描述】:

我有 2 个这样的scipy.sparse.csr_matrix

A = [ 1 0 1 0 0 1
      1 0 0 1 0 0
      0 1 0 0 0 0 ]

B = [ 1 0 1 0 1 1
      1 1 0 1 0 0
      1 1 1 0 0 0 ]

我愿意得到出现在 B 中但不在 A 中的“新的”。

C = [ 0 0 0 0 1 0
      0 1 0 0 0 0
      1 0 1 0 0 0 ]

【问题讨论】:

    标签: python scipy sparse-matrix


    【解决方案1】:

    IIUC 应该很简单:

    In [98]: C = B - A
    
    In [99]: C
    Out[99]:
    <3x6 sparse matrix of type '<class 'numpy.int32'>'
            with 4 stored elements in Compressed Sparse Row format>
    
    In [100]: C.A
    Out[100]:
    array([[0, 0, 0, 0, 1, 0],
           [0, 1, 0, 0, 0, 0],
           [1, 0, 1, 0, 0, 0]], dtype=int32)
    

    【讨论】:

      猜你喜欢
      • 2016-10-29
      • 2019-08-09
      • 1970-01-01
      • 2017-12-04
      • 2014-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多