[SciPy-user] Construct sparse matrix from sparse blocks

Neilen Marais nmarais at sun.ac.za
Fri Feb 8 16:42:13 EST 2008


Nathan,

On Fri, 08 Feb 2008 15:08:30 -0600, Nathan Bell wrote:

> Regarding names, we already have spkron ~= kron and spdiags ~= diag. I
> think we'll have to abandon this approach for the proposed functions
> since spbmat, sphstack, spvstack  are terrible :)
> 
> Which is better,
> 
>   column_stack_sparse
>   row_stack_sparse
>   block_matrix_sparse
> 
> or
> 
>   sparse_column_stack
>   sparse_row_stack
>   sparse_block_matrix
 
> I prefer the XXX_sparse format since it aids tab completion. 
> Suggestions?

All else being equal I prefer verbose and tab-completable, although it 
can get a bit much. I'm actually in favour of Anne's suggestion of using 
namespaces, though I'd put them in the sparse, rather than splinalg 
namespaces. I envision working like this:

import scipy.sparse as sp
import numpy as N

# sparse stuff
A = sp.hstack(....) 
B = sp.bmat(....)

# dense (like me) stuff
D = N.hstack(.....)

etc.

or this:

from scipy.sparse import hstack as sphstack

if that's your bag....

While the original numpy names are a bit concise, I think consistency 
goes along way. This let's us use namespaces to combine brevity with 
explicitness. In the immortal words of import this:

Explicit is better than implicit.
Namespaces are one honking great idea -- let's do more of those!

</zen_koan> ;)

Regards
Neilen




More information about the SciPy-User mailing list