np.array_equal for sparse arrays

Michael Lamparski <[email protected]>
Newsgroups gmane.comp.python.scientific.user
Message-ID <CAGfQJGEzUstj0MJjBeGKM1-Y8oz_p3UtVf1KJF2H-_a6ChQBaw@mail.gmail.com>
Hello everyone,

I feel like I am missing something.  It seems that sparse matrices have no
'any' method or anything useful regarding equality.  Is there not a better
way to write this?

def sparse_equal(a, b):
    """
    Equality test for sparse matrices which performs standard floating
point equality,
    allows mismatched types, considers missing elements equal to zero, and
    requires identical shape (no broadcasting)
    """
    return a.shape == b.shape and not (a != b).data.any()

(I suppose I could also write 'not (a != b).nnz', since the implementation
of != appears to eliminate zeros, but I'm not sure if I should be relying
on that)

---
Michael

_______________________________________________
SciPy-User mailing list
[email protected]
https://mail.python.org/mailman/listinfo/scipy-user
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.