Skip to content

Instantly share code, notes, and snippets.

@chelseatroy
Last active September 26, 2018 04:08
Show Gist options
  • Save chelseatroy/105adcca9ef82d18c52de043bfe528fb to your computer and use it in GitHub Desktop.
Save chelseatroy/105adcca9ef82d18c52de043bfe528fb to your computer and use it in GitHub Desktop.
nonzero alternative implementation
class coo_1d(_data_matrix, ...):
...
def row(self):
return np.zeros(self.col.shape[0])
def nonzero(self):
...
nz_mask = A.data != 0
return (None, A.col[nz_mask])
class coo_2d(_data_matrix, ...):
...
def nonzero(self):
...
A = self.tocoo()
nz_mask = A.data != 0
return (A.row[nz_mask], A.col[nz_mask])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment