Skip to content

Instantly share code, notes, and snippets.

@chelseatroy
Last active September 26, 2018 03:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chelseatroy/64dd62f079bdb66d224160fd9d485fb2 to your computer and use it in GitHub Desktop.
Save chelseatroy/64dd62f079bdb66d224160fd9d485fb2 to your computer and use it in GitHub Desktop.
coo_matrix initializer
class coo_matrix(_data_matrix, _minmax_mixin):
...
format = 'coo'
def __init__(self, arg1, shape=None, dtype=None, copy=False):
_data_matrix.__init__(self)
if isinstance(arg1, tuple):
...
else:
if isspmatrix(arg1):
...
else:
#dense argument
M = np.atleast_2d(np.asarray(arg1))
if M.ndim != 2:
raise TypeError('expected dimension <= 2 array or matrix')
else:
self._shape = check_shape(M.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