def tocoo(self, copy=True): """Return a COOrdinate representation of this matrix When copy=False the index and data arrays are not copied. """ major_dim, minor_dim = self._swap(self.shape) data = self.data minor_indices = self.indices if copy: data = data.copy() minor_indices = minor_indices.copy() major_indices = np.empty(len(minor_indices), dtype=np.intc) sparsetools.expandptr(major_dim, self.indptr, major_indices) row, col = self._swap((major_indices, minor_indices)) from coo import coo_matrix return coo_matrix((data, (row, col)), self.shape)
def tocoo(self,copy=True): """Return a COOrdinate representation of this matrix When copy=False the index and data arrays are not copied. """ major_dim,minor_dim = self._swap(self.shape) data = self.data minor_indices = self.indices if copy: data = data.copy() minor_indices = minor_indices.copy() major_indices = np.empty(len(minor_indices), dtype=np.intc) sparsetools.expandptr(major_dim,self.indptr,major_indices) row,col = self._swap((major_indices,minor_indices)) from coo import coo_matrix return coo_matrix((data,(row,col)), self.shape)