开发者

How to efficiently add sparse matrices in Python

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

I have a program that breaks a big task into subtasks and distributes them across several CPUs. Each subtask yields a result (a scipy sparse matrix formatted as: lil_matrix).

The sparse matrix dimensions are: 100000x500000 , which is quite huge, so I really need the most efficient way to sum all the resulting spa开发者_如何学Crse matrices into a single sparse matrix, using some C-compiled method or something.


Have you tried timing the simplest method?

matrix_result = matrix_a + matrix_b

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

matrix_result = (matrix_a.tocsr() + matrix_b.tocsr()).tolil()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜