[SciPy-Dev] Sparse Matrix Prototype

Nathaniel Smith njs@pobox....
Tue Mar 5 08:18:51 CST 2013

On Tue, Mar 5, 2013 at 1:57 PM, Daniel Smith <smith.daniel.br@gmail.com> wrote:
> Hi,
> I've been working on adding fancy indexing to the LIL sparse matrix
> class and have run into a problem. Judging from the tests, no decision
> has been made as to what NumPy structure the class should replicate.
> In particular, some of the tests assume ndarray behavior, and others
> assume matrix behavior. The biggest difference is in row/column vector
> behavior. Take for example:
> A = np.zeros((5, 5))
> B = np.matrix(A)
> A[:, 1]
>     array([0, 0, 0, 0, 0])
> B[:, 1]
>     matrix([ [0], [0], [0], [0], [0] ])
> Since NumPy is encouraging people to use ndarrays over matrices, it
> might make sense to reproduce the ndarray behavior. However, since the
> class has other matrix-specific behavior, e.g. being only
> two-dimensional, it might be confusing to have the class behave like
> an ndarray in other ways. Until a decision is made, no version of the
> class will pass all the tests as currently written. Any input would be
> greatly appreciated.

I find the "matrixness" of sparse matrices to be constantly annoying
and a source of tons of special cases in code that wants to handle
both sparse and dense matrices... but it is what it is. If they can't
act like ndarrays, better they act like np.matrix's than like some
weird mash-up of the two. And in particular the key thing for this
indexing example is that we *can't* return a sparse 1-d ndarray-alike,
right, because we have no structure to represent sparse 1-d things?


More information about the SciPy-Dev mailing list