Skip to content

Instantly share code, notes, and snippets.

@chelseatroy
Created September 26, 2018 03:56
Show Gist options
  • Save chelseatroy/806c86d8b59c502f9d7cd16474e8676a to your computer and use it in GitHub Desktop.
Save chelseatroy/806c86d8b59c502f9d7cd16474e8676a to your computer and use it in GitHub Desktop.
alternative coo implementation
class coo_matrix(_data_matrix, _minmax_mixin):
...
format = 'coo'
def __init__(self, arg1, shape=None, dtype=None, copy=False):
...
else:
#dense argument
array_data = np.asarray(arg1)
if array_data.ndim = 1:
M = coo_1d(M)
if array_data.ndim = 2:
M = coo_2d(M)
if array_data.ndim > 2:
raise TypeError('expected dimension <= 2 array or matrix')
else:
self._shape = check_shape(array_data.shape)
self.row, self.col = M.nonzero()
self.data = M[self.row, self.col]
self.has_canonical_format = True
if dtype is not None:
self.data = self.data.astype(dtype, copy=False)
self._check()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment