MCPcopy Create free account
hub / github.com/numpy/numpy / _add_keepdims

Function _add_keepdims

numpy/lib/tests/test_shape_base.py:19–27  ·  view source on GitHub ↗

hack in keepdims behavior into a function taking an axis

(func)

Source from the content-addressed store, hash-verified

17
18
19def _add_keepdims(func):
20 """ hack in keepdims behavior into a function taking an axis """
21 @functools.wraps(func)
22 def wrapped(a, axis, **kwargs):
23 res = func(a, axis=axis, **kwargs)
24 if axis is None:
25 axis = 0 # res is now a scalar, so we can insert this anywhere
26 return np.expand_dims(res, axis=axis)
27 return wrapped
28
29
30class TestTakeAlongAxis:

Callers 2

test_argequivalentMethod · 0.85
test_replace_maxMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected