SpPy is a fast sparse matrix/array library written in Python and based on the C++ matrix library Eigen. A sparse matrix is one in which many of the elements are zeros, and by storing only non-zero elements, one can often make memory and computational savings over dense matrices which store all elements. The library supports (compressed) sparse matrices, sparse vectors and a number of linear algebra operations (such as the randomised SVD and matrix norm). Furthermore, SpPy has a similar interface to numpy so that existing code requires minimal change to work with sparse matrices and vectors.
First, read the installation guide in the reference documentation linked below. More complete documentation is forthcoming, but for now here are some examples.
>>> import numpy
>>> from sppy import csarray
>>> #Create a new column major dynamic array of float type
>>> B = csarray((5, 5), storagetype="col")
>>> B[3, 3] = -0.2
>>> B[0, 4] = -1.23
>>> print(B.shape)
(5, 5)
>>> print(B.size)
25
>>> print(B.getnnz())
2
>>> print(B)
csarray dtype:float64 shape:(5, 5) non-zeros:2 storage:col
(3, 3) -0.2
(0, 4) -1.23
>>> B[numpy.array([0, 1]), numpy.array([0,1])] = 27
>>> print(B)
csarray dtype:float64 shape:(5, 5) non-zeros:4 storage:col
(0, 0) 27.0
(1, 1) 27.0
(3, 3) -0.2
(0, 4) -1.23
>>> print(B.sum())
52.57
User guide:
Reference guide: