[SciPy-User] "Zero"-shape sparse matrices
Jaakko Luttinen
jaakko.luttinen at aalto.fi
Tue Feb 21 10:58:37 EST 2012
On 02/21/2012 05:00 PM, Warren Weckesser wrote:
>
>
> On Tue, Feb 21, 2012 at 7:23 AM, Jaakko Luttinen
> <jaakko.luttinen at aalto.fi <mailto:jaakko.luttinen at aalto.fi>> wrote:
>
> On 02/17/2012 06:48 PM, Christopher Mutel wrote:
> > On Fri, Feb 17, 2012 at 4:32 PM, eat <e.antero.tammi at gmail.com
> <mailto:e.antero.tammi at gmail.com>> wrote:
> >> On Thu, Feb 16, 2012 at 5:44 PM, Jaakko Luttinen
> <jaakko.luttinen at aalto.fi <mailto:jaakko.luttinen at aalto.fi>>
> >> wrote:
> >>> 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?
> >
> > I am not an expert, but it is my understanding that the sparse matrix
> > implementations in SciPy assume precisely two dimensions. One
> > dimension having a size of 0 would break all the assumptions of this
> > code. The NumPy array class is a much more generic container, and was
> > designed from the beginning to allow a number of slicing and
> > dimensionality tricks (see the documentation on numpy striding). You
> > can search through the mailing list from a few years ago to find a
> > discussion about three dimensional sparse matrices, and the conclusion
> > was the same: SciPy supports 2-d (in the sense of two real dimensions)
> > sparse matrices only.
>
> Thanks for your answer!
>
> I think a matrix with shape (10,0) would be as "2-d" as a (10,1) shaped
> matrix. Both have two dimensions, but neither one has both axes longer
> than 1. I don't mean to consider 0-d, 1-d, 3-d or N-d matrices, but
> empty 2-d matrices. I just don't see why there is this limitation for
> sparse matrices that zero is not a valid length for an axis.
>
>
>
> In principle, sparse matrices should behave as much like dense matrices
> as possible. Since numpy ndarrays and matrices allow a dimension to
> have length 0, it is a reasonable expectation for sparse matrices to
> allow this also. Could you file a ticket for this? Click on the "bug
> reports" link here: http://projects.scipy.org/scipy
Ok, thanks!
http://projects.scipy.org/scipy/ticket/1602
-Jaakko
More information about the SciPy-User
mailing list