[SciPy-User] "Zero"-shape sparse matrices

Jaakko Luttinen jaakko.luttinen@aalto...
Tue Feb 21 07:15:06 CST 2012


On 02/17/2012 05:32 PM, eat wrote:
> Hi,
> 
> Perhaps a slightly OT (and I'm not really answering to your question), but
> 
> On Thu, Feb 16, 2012 at 5:44 PM, Jaakko Luttinen
> <jaakko.luttinen@aalto.fi <mailto:jaakko.luttinen@aalto.fi>> wrote:
> 
>     Hi!
> 
>     To make a long story short, Scipy doesn't seem to allow sparse matrices
>     that have length zero on any of the axes. For instance:
>     C = numpy.ones((0,0))
>     K = scipy.sparse.csc_matrix(C)
>     ValueError: invalid shape
> 
>     It is possible to create a "zero"-shape dense matrix but not sparse.
>     Why? To me, this seems like a bug.. Is it so?
> 
> what would you expect a  "zero"-shape sparse (or dense)
> matrix actually represent?

"Zero"-shape matrix would represent an empty matrix which has a correct
shape for some operations. This is very convenient for generic code
because I don't need to check if some dimension has zero length.

For instance:
- horizontal concatenation of (10,3), (10,2) and (10,0) shaped matrices
would work and produce a (10,5) shaped matrix.
- forming a block matrix from four matrices having shapes (0,0), (0,20),
(10,0) and (10,20) would produce a (10,20) matrix using numpy.bmat.

Regards,
Jaakko


More information about the SciPy-User mailing list