
Hello. I am very interested in implementing efficient operations on sparse matrices from scipy, such as: interp2, imresize, imfilter, mean2, gradient - all these functions are actually the ones from Matlab, used in computer vision (you can google to see exactly what they do). It seems it's not very difficult - I used also some information from an earlier email on this list (see below). Did anybody else try something similar with the sparse matrices in scipy? Thank you, Alex
On Fri, Oct 10, 2014 at 12:00 PM, Saullo Castro <saullogiovani <at> gmail.com> wrote: I developed a function (shown below) to check if a sparse matrix is symmetric and would like to know if the community is interested to include in scipy.sparse.
Regards, Saullo
def is_symmetric(m): """Check if a sparse matrix is symmetric """ if m.shape[0] != m.shape[1]: raise ValueError('m must be a square matrix')
if not isinstance(m, coo_matrix): m = coo_matrix(m)
r, c, v = m.row, m.col, m.data tril_no_diag = r > c triu_no_diag = c > r
if triu_no_diag.sum() != tril_no_diag.sum(): return False
rl = r[tril_no_diag] cl = c[tril_no_diag] vl = v[tril_no_diag] ru = r[triu_no_diag] cu = c[triu_no_diag] vu = v[triu_no_diag]
sortl = np.lexsort((cl, rl)) sortu = np.lexsort((ru, cu)) vl = vl[sortl] vu = vu[sortu]
check = np.allclose(vl, vu)
return check

On 23/12/14 18:11, Alex Susu wrote:
I am very interested in implementing efficient operations on sparse matrices from scipy, such as: interp2, imresize, imfilter, mean2, gradient - all these functions are actually the ones from Matlab, used in computer vision (you can google to see exactly what they do).
They are not from Matlab. But you will find cases where functions in Matlab and NumPy/SciPy have the same name, for obvious reasons. Sturla
participants (2)
-
Alex Susu
-
Sturla Molden