Check if two scipy.sparse.csr_matrix are equal

前端 未结 2 1234
清歌不尽
清歌不尽 2020-12-10 10:55

I want to check if two csr_matrix are equal.

If I do:

x.__eq__(y)

I get:

raise ValueError(\"The truth value of an a         


        
2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-10 11:31

    SciPy and Numpy Hybrid Method

    What worked best for my case was (using a generic code example):

    bool_answer = np.arrays_equal(sparse_matrix_1.todense(), sparse_matrix_2.todense())
    

    You might need to pay attention to the equal_nan parameter in np.arrays_equal

    The following doc references helped me get there: CSR Sparse Matrix Methods CSC Sparse Matrix Methods Numpy arrays_equal method SciPy todense method

提交回复
热议问题