How to effectively add sparse matrices in Python

I want to know how to efficiently add sparse matrices in Python.

I have a program that breaks down a large task into subtasks and distributes them across several processors. Each subtask gives a result (scipy sparse matrix, formatted as: lil_matrix ).

Rare matrix sizes: 100000x500000, which is quite large, so I really need the most efficient way to sum all the resulting sparse matrices into a single sparse matrix using some C-compiled method or something like that.

+4
source share
1 answer

Have you tried the simplest method?

 matrix_result = matrix_a + matrix_b 

The documentation warns that this may be slow for LIL matrices, suggesting that the following may be faster:

 matrix_result = (matrix_a.tocsr() + matrix_b.tocsr()).tolil() 
+8
source

Source: https://habr.com/ru/post/1333834/


All Articles