#NEWLINE# def tocoo( self , copy = False ) : #NEWLINE# #INDENT# ( num_rows , num_cols ) = self . shape #NEWLINE# ( num_offsets , offset_len ) = self . data . shape #NEWLINE# offset_inds = np . arange ( offset_len ) #NEWLINE# row = ( offset_inds - self . offsets [ : , None ] ) #NEWLINE# mask = ( row >= 0 ) #NEWLINE# mask &= ( row < num_rows ) #NEWLINE# mask &= ( offset_inds < num_cols ) #NEWLINE# mask &= ( self . data != 0 ) #NEWLINE# row = row [ mask ] #NEWLINE# col = np . tile ( offset_inds , num_offsets ) [ mask . ravel ( ) ] #NEWLINE# data = self . data [ mask ] #NEWLINE# from . coo import coo_matrix #NEWLINE# A = coo_matrix ( ( data , ( row , col ) ) , shape = self . shape , dtype = self . dtype ) #NEWLINE# A . has_canonical_format = True #NEWLINE# return A