[SciPy-user] Construct sparse matrix from sparse blocks
David Warde-Farley
dwf at cs.toronto.edu
Thu Feb 7 10:45:32 EST 2008
On 7-Feb-08, at 10:39 AM, Neilen Marais wrote:
> I have several sparse blocks defined separately. E.eg.
>
> A_aa, A_ab, A_ba, A_bb, A_cc, I want to construct a new sparse matrix
> like this:
>
> A = [A_aa A_ab 0 ]
> [A_ba A_bb 0 ]
> [0 0 A_cc]
What scipy.sparse type are you using to store them, or if you haven't
written that part yet, how are these matrices represented?
If they're stored as a vector of row indices, a vector of column
indices and a vector of values (as in the scipy.sparse.coo_matrix )
then constructing it should be as straightforward as doing a few array
concatenations (or copies). This format can then be efficiently
converted to CSR or CSC with the tocsr() or tocsc() methods, which is
the format you want it in if you're going to be doing any multiplies,
etc.
David
More information about the SciPy-User
mailing list