#NEWLINE# def mode( a , axis = 0 ) : #NEWLINE# #INDENT# '\n    Returns an array of the modal (most common) value in the passed array.\n\n    Parameters\n    ----------\n    a : array_like\n        n-dimensional array of which to find mode(s).\n    axis : int or None, optional\n        Axis along which to operate. Default is 0. If None, compute over\n        the whole array `a`.\n\n    Returns\n    -------\n    mode : ndarray\n        Array of modal values.\n    count : ndarray\n        Array of counts for each mode.\n\n    Notes\n    -----\n    For more details, see `stats.mode`.\n\n    ' #NEWLINE# ( a , axis ) = _chk_asarray ( a , axis ) #NEWLINE# def _mode1D( a ) : #NEWLINE# #INDENT# ( rep , cnt ) = find_repeats ( a ) #NEWLINE# if ( not cnt . ndim ) : #NEWLINE# #INDENT# return ( 0 , 0 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if cnt . size : #NEWLINE# #INDENT# return ( rep [ cnt . argmax ( ) ] , cnt . max ( ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# not_masked_indices = ma . flatnotmasked_edges ( a ) #NEWLINE# first_not_masked_index = not_masked_indices [ 0 ] #NEWLINE# return ( a [ first_not_masked_index ] , 1 ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( axis is None ) : #NEWLINE# #INDENT# output = _mode1D ( ma . ravel ( newshape ) ) #NEWLINE# output = ( ma . array ( output [ 0 ] ) , ma . array ( output [ 1 ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# output = ma . apply_along_axis ( _mode1D , axis , a ) #NEWLINE# newshape = list ( a . shape ) #NEWLINE# newshape [ axis ] = 1 #NEWLINE# slices = ( [ slice ( None ) ] * output . ndim ) #NEWLINE# slices [ axis ] = 0 #NEWLINE# modes = output [ tuple ( slices ) ] . reshape ( newshape ) #NEWLINE# slices [ axis ] = 1 #NEWLINE# counts = output [ tuple ( slices ) ] . reshape ( newshape ) #NEWLINE# output = ( modes , counts ) #NEWLINE# #UNINDENT# return ModeResult ( * output )