[SciPy-Dev] utility for composing sparse matrices
Robert Cimrman
cimrman3@ntc.zcu...
Mon Sep 20 03:26:58 CDT 2010
FYI: I have created a function that creates a sparse matrix from sparse
(or dense) blocks, somewhat in the spirit of np.r_ and friends, see the
example below.
Shall we add it to scipy.sparse? It may help to go around some of the
fancy-indexing limitations.
r.
In [1]: from compose_sparse import compose_sparse
In [2]: %doctest_mode
*** Pasting of code with ">>>" or "..." has been enabled.
Exception reporting mode: Plain
Doctest mode is: ON
>>> >>> import scipy.sparse as sps
>>> >>> A = sps.csr_matrix([[1, 0], [0, 1]])
>>> >>> B = sps.coo_matrix([[1, 1]])
>>> >>> K = compose_sparse([[A, B.T], [B, 0]])
>>> >>> print K.todense()
--> print(K.todense())
[[1 0 1]
[0 1 1]
[1 1 0]]
-------------- next part --------------
A non-text attachment was scrubbed...
Name: compose_sparse.py
Type: text/x-python
Size: 2835 bytes
Desc:
Url : http://mail.scipy.org/pipermail/scipy-dev/attachments/20100920/7afd32af/attachment.py
More information about the SciPy-Dev
mailing list