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

Function apply_over_axes

numpy/ma/extras.py:453–475  ·  view source on GitHub ↗

(This docstring will be overwritten)

(func, a, axes)

Source from the content-addressed store, hash-verified

451
452
453def apply_over_axes(func, a, axes):
454 """
455 (This docstring will be overwritten)
456 """
457 val = asarray(a)
458 N = a.ndim
459 if array(axes).ndim == 0:
460 axes = (axes,)
461 for axis in axes:
462 if axis < 0:
463 axis = N + axis
464 args = (val, axis)
465 res = func(*args)
466 if res.ndim == val.ndim:
467 val = res
468 else:
469 res = ma.expand_dims(res, axis)
470 if res.ndim == val.ndim:
471 val = res
472 else:
473 raise ValueError("function is not returning "
474 "an array of the correct shape")
475 return val
476
477
478if apply_over_axes.__doc__ is not None:

Callers 1

test_basicMethod · 0.90

Calls 3

asarrayFunction · 0.70
arrayFunction · 0.70
funcFunction · 0.50

Tested by 1

test_basicMethod · 0.72