#NEWLINE# def __init__( self , matrix , row2word = None , col2word = None ) : #NEWLINE# #INDENT# '\n        Initialize a Matrix instance.\n        :param matrix: A matrix of dict (row) of dict (column) of values, or of type scipy.sparse.spmatrix.\n                       If matrix is not dict of dict, row2word and col2word must be set.\n        :param row2word: List of words, corresponding to each row of the matrix.\n        :param col2word: List of words, corresponding to each column of the matrix.\n        :return:\n        ' #NEWLINE# if isinstance ( matrix , dict ) : #NEWLINE# #INDENT# ( matrix , row2word , col2word ) = _dict2matrix ( matrix ) #NEWLINE# #UNINDENT# if ( not isinstance ( matrix , sp . spmatrix ) ) : #NEWLINE# #INDENT# self . matrix = sp . csr_matrix ( matrix ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . matrix = matrix . tocsr ( ) #NEWLINE# #UNINDENT# if ( ( not isinstance ( row2word , list ) ) or ( not isinstance ( col2word , list ) ) ) : #NEWLINE# #INDENT# raise TypeError ( 'Row2word and col2word needs to be of type list, not {} and {}' . format ( type ( row2word ) , type ( col2word ) ) ) #NEWLINE# #UNINDENT# if ( len ( row2word ) != matrix . shape [ 0 ] ) : #NEWLINE# #INDENT# raise ValueError ( 'Matrix row is of length {}, but row2word is of length {}' . format ( matrix . shape [ 0 ] , len ( row2word ) ) ) #NEWLINE# #UNINDENT# if ( len ( col2word ) != matrix . shape [ 1 ] ) : #NEWLINE# #INDENT# raise ValueError ( 'Matrix column is of length {}, but col2word is of length {}' . format ( matrix . shape [ 1 ] , len ( col2word ) ) ) #NEWLINE# #UNINDENT# if ( not ( self . matrix . dtype in ( np . double , np . bool ) ) ) : #NEWLINE# #INDENT# self . matrix = self . matrix . astype ( np . double ) #NEWLINE# #UNINDENT# self . _row2word = row2word #NEWLINE# self . _col2word = col2word #NEWLINE# self . _word2row = None #NEWLINE# self . _word2col = None #NEWLINE# self . _display_max_rows = 10 #NEWLINE# self . _display_max_cols = 7