You can use c.nonzero() method:
>>> from scipy.sparse import lil_eye >>> c = lil_eye((4, 10))
You do not need to calculate the matrix c to determine the indices of nonzero elements in c = a - b ; you can do (a != b).nonzero() :
>>> a = np.random.random_integers(2, size=(4,4)) >>> b = np.random.random_integers(2, size=(4,4)) >>> (a != b).nonzero() (array([0, 0, 1, 1, 1, 2, 3]), array([1, 2, 1, 2, 3, 2, 0])) >>> a - b array([[ 0, 1, 1, 0], [ 0, 1, -1, -1], [ 0, 0, 1, 0], [-1, 0, 0, 0]])
source share