Scipy sparse matrices – purpose and usage of different implementations

Sorry if I’m not answering this completely enough, but hopefully I can provide some insight. CSC (Compressed Sparse Column) and CSR (Compressed Sparse Row) are more compact and efficient, but difficult to construct “from scratch”. Coo (Coordinate) and DOK (Dictionary of Keys) are easier to construct, and can then be converted to CSC or CSR … Read more

How to elementwise-multiply a scipy.sparse matrix by a broadcasted dense 1d array?

I replied over at scipy.org as well, but I thought I should add an answer here, in case others find this page when searching. You can turn the vector into a sparse diagonal matrix and then use matrix multiplication (with *) to do the same thing as broadcasting, but efficiently. >>> d = ssp.lil_matrix((3,3)) >>> … Read more

Concatenate sparse matrices in Python using SciPy/Numpy

You can use the scipy.sparse.hstack to concatenate sparse matrices with the same number of rows (horizontal concatenation): from scipy.sparse import hstack hstack((X, X2)) Similarly, you can use scipy.sparse.vstack to concatenate sparse matrices with the same number of columns (vertical concatenation). Using numpy.hstack or numpy.vstack will create an array with two sparse matrix objects.

LCP with sparse matrix

This problem has a very efficient (linear time) solution, though it requires a bit of discussion… Zeroth: clarifying the problem / LCP Per clarifications in the comments, @FooBar says the original problem is elementwise min; we need to find a z (or v) such that either the left argument is zero and the right argument … Read more