B = L.copy()
for row in range(0,B.shape[0]):
if np.unique(B.getrow(row).data).size == 1:
B.data[B.indptr[row]:B.indptr[row+1]] = 0
return matrix_coverage(sparse_nonzero(B))
After Change
B_nonzero = sparse_nonzero(B)
B_abs = sparse_abs(L)
with np.errstate(divide="ignore"): // Suppresses warning occuring when all labeles for candidate are 0
return np.ravel(np.where(np.logical_or(np.mod(B.sum(axis=1),B_nonzero.sum(axis=1)) != 0,\
B_abs.sum(axis=1) != sparse_abs(B.sum(axis=1)) ),1,0).T * B_nonzero / float(B.shape[0]))
def matrix_tp(L, labels):