def keepdims_wrapper(a_callable):
 if ('keepdims' in getargspec(a_callable).args):
  return a_callable
 @wraps(a_callable)
 def keepdims_wrapped_callable(x, axis=None, keepdims=None, *args, **kwargs):
  r = a_callable(x, axis=axis, *args, **kwargs)
  if (not keepdims):
   return r
  axes = axis
  if (axes is None):
   axes = range(x.ndim)
  if (not isinstance(axes, (Container, Iterable, Sequence))):
   axes = [axes]
  r_slice = tuple()
  for each_axis in range(x.ndim):
   if (each_axis in axes):
    r_slice += (None,)
   else:
    r_slice += (slice(None),)
  r = r[r_slice]
  return r
 return keepdims_wrapped_callable

def keepdims_wrapper ( a_callable ) : if ( 'keepdims' in getargspec ( a_callable ) . args ) : return a_callable @ wraps ( a_callable ) def keepdims_wrapped_callable ( x , axis = None , keepdims = None , * args , ** kwargs ) : r = a_callable ( x , axis = axis , * args , ** kwargs ) if ( not keepdims ) : return r axes = axis if ( axes is None ) : axes = range ( x . ndim ) if ( not isinstance ( axes , ( Container , Iterable , Sequence ) ) ) : axes = [ axes ] r_slice = tuple ( ) for each_axis in range ( x . ndim ) : if ( each_axis in axes ) : r_slice += ( None , ) else : r_slice += ( slice ( None ) , ) r = r [ r_slice ] return r return keepdims_wrapped_callable
a wrapper for functions that dont provide keepdims to ensure that they do .