Popular recipes tagged "meta:requires=colormap"http://code.activestate.com/recipes/tags/meta:requires=colormap/2005-04-18T00:17:29-07:00ActiveState Code Recipessparse: A dictionary based sparse matrix class (Python)
2005-04-18T00:17:29-07:00Alexander Pletzerhttp://code.activestate.com/recipes/users/98107/http://code.activestate.com/recipes/52275-sparse-a-dictionary-based-sparse-matrix-class/
<p style="color: grey">
Python
recipe 52275
by <a href="/recipes/users/98107/">Alexander Pletzer</a>
(<a href="/recipes/tags/graphics/">graphics</a>).
Revision 6.
</p>
<p>'sparse' is a matrix class based on a dictionary to store data using 2-element tuples (i,j)
as keys (i is the row and j the column index). The common matrix operations such as
'dot' for the inner product, multiplication/division by a scalar, indexing/slicing, etc. are
overloaded for convenience. When used in conjunction with the 'vector' class, 'dot'
products also apply between matrics and vectors. Two methods, 'CGsolve' and
'biCGsolve', are provided to solve linear systems. Tested using Python 2.2.</p>