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

Function _arraymethod

numpy/ma/core.py:2544–2586  ·  view source on GitHub ↗

Return a class method wrapper around a basic array method. Creates a class method which returns a masked array, where the new ``_data`` array is the output of the corresponding basic method called on the original ``_data``. If `onmask` is True, the new mask is the output of th

(funcname, onmask=True)

Source from the content-addressed store, hash-verified

2542
2543
2544def _arraymethod(funcname, onmask=True):
2545 """
2546 Return a class method wrapper around a basic array method.
2547
2548 Creates a class method which returns a masked array, where the new
2549 ``_data`` array is the output of the corresponding basic method called
2550 on the original ``_data``.
2551
2552 If `onmask` is True, the new mask is the output of the method called
2553 on the initial mask. Otherwise, the new mask is just a reference
2554 to the initial mask.
2555
2556 Parameters
2557 ----------
2558 funcname : str
2559 Name of the function to apply on data.
2560 onmask : bool
2561 Whether the mask must be processed also (True) or left
2562 alone (False). Default is True. Make available as `_onmask`
2563 attribute.
2564
2565 Returns
2566 -------
2567 method : instancemethod
2568 Class method wrapper of the specified basic array method.
2569
2570 """
2571 def wrapped_method(self, *args, **params):
2572 result = getattr(self._data, funcname)(*args, **params)
2573 result = result.view(type(self))
2574 result._update_from(self)
2575 mask = self._mask
2576 if not onmask:
2577 result.__setmask__(mask)
2578 elif mask is not nomask:
2579 # __setmask__ makes a copy, which we don't want
2580 result._mask = getattr(mask, funcname)(*args, **params)
2581 return result
2582 methdoc = getattr(ndarray, funcname, None) or getattr(np, funcname, None)
2583 if methdoc is not None:
2584 wrapped_method.__doc__ = methdoc.__doc__
2585 wrapped_method.__name__ = funcname
2586 return wrapped_method
2587
2588
2589class MaskedIterator:

Callers 1

MaskedArrayClass · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected