[SciPy-User] "Zero"-shape sparse matrices
Tue Feb 21 07:23:28 CST 2012
On 02/17/2012 06:48 PM, Christopher Mutel wrote:
> On Fri, Feb 17, 2012 at 4:32 PM, eat <firstname.lastname@example.org> wrote:
>> On Thu, Feb 16, 2012 at 5:44 PM, Jaakko Luttinen <email@example.com>
>>> 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.
More information about the SciPy-User