Last active
September 26, 2018 03:22
-
-
Save chelseatroy/64dd62f079bdb66d224160fd9d485fb2 to your computer and use it in GitHub Desktop.
coo_matrix initializer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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