[SciPy-user] fast max() on sparse matrices

Nathan Bell wnbell at gmail.com
Mon Jan 5 17:40:44 EST 2009


On Mon, Jan 5, 2009 at 4:43 PM, nicky van foreest <vanforeest at gmail.com> wrote:
>
> A few days ago I encountered just the same problem, and solved by
> taking the max of the values(), just as suggested below. However, it
> took me some minutes to fiugre this out, and I first, of course, tried
> the max() function. Thus, I suggest that the max function will be
> added to the sparse class. Is there a reason not to do so?
>

Hi Nicky,

It should be added, but it's not as straightforward as you might think.

For conformity with dense matrices, max() should return zero if the
nonzero entries of the matrix are all negative and there is at least
one missing value in the matrix.  This might surprise people who
expect the largest nonzero value instead.  For instance,
csr_matrix([[0,-1]]).max() should be 0.

Another minor problem is that some matrices permit duplicate entries.
Currently, we implicitly sum duplicate values together (e.g. when
computing sparse matrix-vector products) and when converting to other
formats.  We'd probably want to make max() and min() agree with this
behavior.

-- 
Nathan Bell wnbell at gmail.com
http://graphics.cs.uiuc.edu/~wnbell/



More information about the SciPy-User mailing list