def coarsen(reduction, x, axes, trim_excess=False):
 for i in range(x.ndim):
  if (i not in axes):
   axes[i] = 1
 if trim_excess:
  ind = tuple(((slice(0, (- (d % axes[i]))) if (d % axes[i]) else slice(None, None)) for (i, d) in enumerate(x.shape)))
  x = x[ind]
 newshape = tuple(concat([((x.shape[i] / axes[i]), axes[i]) for i in range(x.ndim)]))
 return reduction(x.reshape(newshape), axis=tuple(range(1, (x.ndim * 2), 2)))

def coarsen ( reduction , x , axes , trim_excess = False ) : for i in range ( x . ndim ) : if ( i not in axes ) : axes [ i ] = 1 if trim_excess : ind = tuple ( ( ( slice ( 0 , ( - ( d % axes [ i ] ) ) ) if ( d % axes [ i ] ) else slice ( None , None ) ) for ( i , d ) in enumerate ( x . shape ) ) ) x = x [ ind ] newshape = tuple ( concat ( [ ( ( x . shape [ i ] / axes [ i ] ) , axes [ i ] ) for i in range ( x . ndim ) ] ) ) return reduction ( x . reshape ( newshape ) , axis = tuple ( range ( 1 , ( x . ndim * 2 ) , 2 ) ) )
coarsen array by applying reduction to fixed size neighborhoods parameters reduction: function function like np .