#NEWLINE# def _most_frequent( array , extra_value , n_repeat ) : #NEWLINE# #INDENT# 'Compute the most frequent value in a 1d array extended with\n       [extra_value] * n_repeat, where extra_value is assumed to be not part\n       of the array.' #NEWLINE# if ( array . size > 0 ) : #NEWLINE# #INDENT# mode = stats . mode ( array ) #NEWLINE# most_frequent_value = mode [ 0 ] [ 0 ] #NEWLINE# most_frequent_count = mode [ 1 ] [ 0 ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# most_frequent_value = 0 #NEWLINE# most_frequent_count = 0 #NEWLINE# #UNINDENT# if ( ( most_frequent_count == 0 ) and ( n_repeat == 0 ) ) : #NEWLINE# #INDENT# return np . nan #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( most_frequent_count < n_repeat ) : #NEWLINE# #INDENT# return extra_value #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( most_frequent_count > n_repeat ) : #NEWLINE# #INDENT# return most_frequent_value #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( most_frequent_count == n_repeat ) : #NEWLINE# #INDENT# if ( array < extra_value ) : #NEWLINE# #INDENT# return most_frequent_value #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return extra_value