[SciPy-user] New sparse matrix functionality
Robert Cimrman
cimrman3 at ntc.zcu.cz
Mon Feb 27 05:23:32 EST 2006
Hi Ed,
Ed Schofield wrote:
> My branch also changes one aspect of the existing behaviour: the
> todense() method now returns a dense (NumPy) matrix, rather than a dense
> array. Converting to a dense array is now available under a toarray()
> method (or .A attribute) instead. The rationale behind this change is
> to emphasize that sparse matrices are closer to dense matrices than to
> dense arrays in their attributes (e.g. .T for transpose) and behaviour
> (e.g. * means inner product). I've also been careful to make
> multiplication between sparse matrices and dense row or column vectors
> (matrix objects with unit length or height) return matrices of the
> correct dimensions, rather than arrays. Several unit tests relied on
> the old behaviour, and I've changed these accordingly. Most of these
> test changes are just simplifications -- for example
>
> assert_array_equal((a*c).todense(), a.todense() * c)
>
> instead of
>
> assert_array_equal((a*c).todense(), dot(a.todense(), c))
> -- but I'd appreciate some criticism and feedback on which behaviour
> people prefer.
well done! I think it's better your way - if a vector (i.e. 2D array) is
put in, it is expected that a vector gous out as well.
Do you also plan to add the c-based linked-list matrix as in PySparse
(ll_mat.c there)? This could be even faster than using the Python lists
(IMHO...).
> These changes have highlighted a problem present in both the main trunk
> and my branch: that multiplying a dense matrix 'a' by a sparse matrix
> 'b' is not possible using the syntax 'a*b'. I'll follow this up with a
> proposal to numpy-discussion on how we can solve this.
I am very curious how to do this. Surely NumPy will have to be aware of
existence of sparse matrix objects, right?
r.
More information about the SciPy-User
mailing list