#NEWLINE# def _min_or_max_axis( X , axis , min_or_max ) : #NEWLINE# #INDENT# N = X . shape [ axis ] #NEWLINE# if ( N == 0 ) : #NEWLINE# #INDENT# raise ValueError ( 'zero-size array to reduction operation' ) #NEWLINE# #UNINDENT# M = X . shape [ ( 1 - axis ) ] #NEWLINE# mat = ( X . tocsc ( ) if ( axis == 0 ) else X . tocsr ( ) ) #NEWLINE# mat . sum_duplicates ( ) #NEWLINE# ( major_index , value ) = _minor_reduce ( mat , min_or_max ) #NEWLINE# not_full = ( np . diff ( mat . indptr ) [ major_index ] < N ) #NEWLINE# value [ not_full ] = min_or_max ( value [ not_full ] , 0 ) #NEWLINE# mask = ( value != 0 ) #NEWLINE# major_index = np . compress ( mask , major_index ) #NEWLINE# value = np . compress ( mask , value ) #NEWLINE# from scipy.sparse import coo_matrix #NEWLINE# if ( axis == 0 ) : #NEWLINE# #INDENT# res = coo_matrix ( ( value , ( np . zeros ( len ( value ) ) , major_index ) ) , dtype = X . dtype , shape = ( 1 , M ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# res = coo_matrix ( ( value , ( major_index , np . zeros ( len ( value ) ) ) ) , dtype = X . dtype , shape = ( M , 1 ) ) #NEWLINE# #UNINDENT# return res . A . ravel ( )