[SciPy-User] np.array_equal for sparse arrays
Michael Lamparski
diagonaldevice at gmail.com
Thu Sep 13 11:43:34 EDT 2018
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-user/attachments/20180913/e0220354/attachment.html>
More information about the SciPy-User
mailing list