def extrema(input, labels=None, index=None):
 dims = numpy.array(numpy.asarray(input).shape)
 dim_prod = numpy.cumprod(([1] + list(dims[:0:(-1)])))[::(-1)]
 (minimums, min_positions, maximums, max_positions) = _select(input, labels, index, find_min=True, find_max=True, find_min_positions=True, find_max_positions=True)
 if numpy.isscalar(minimums):
  return (minimums, maximums, tuple(((min_positions // dim_prod) % dims)), tuple(((max_positions // dim_prod) % dims)))
 min_positions = [tuple(v) for v in ((min_positions.reshape((-1), 1) // dim_prod) % dims)]
 max_positions = [tuple(v) for v in ((max_positions.reshape((-1), 1) // dim_prod) % dims)]
 return (minimums, maximums, min_positions, max_positions)

def extrema ( input , labels = None , index = None ) : dims = numpy . array ( numpy . asarray ( input ) . shape ) dim_prod = numpy . cumprod ( ( [ 1 ] + list ( dims [ : 0 : ( - 1 ) ] ) ) ) [ : : ( - 1 ) ] ( minimums , min_positions , maximums , max_positions ) = _select ( input , labels , index , find_min = True , find_max = True , find_min_positions = True , find_max_positions = True ) if numpy . isscalar ( minimums ) : return ( minimums , maximums , tuple ( ( ( min_positions // dim_prod ) % dims ) ) , tuple ( ( ( max_positions // dim_prod ) % dims ) ) ) min_positions = [ tuple ( v ) for v in ( ( min_positions . reshape ( ( - 1 ) , 1 ) // dim_prod ) % dims ) ] max_positions = [ tuple ( v ) for v in ( ( max_positions . reshape ( ( - 1 ) , 1 ) // dim_prod ) % dims ) ] return ( minimums , maximums , min_positions , max_positions )
calculate the minimums and maximums of the values of an array at labels .