cf.Data.func¶
-
Data.
func
(f, units=None, out=False, inplace=False, preserve_invalid=False, i=False, **kwargs)[source]¶ Apply an element-wise array operation to the data array.
- Parameters
- f:
function
The function to be applied.
units:
Units
, optionalout: deprecated at version 3.14.0
- inplace:
bool
, optional If True then do the operation in-place and return
None
.- preserve_invalid:
bool
, optional For MaskedArray arrays only, if True any invalid values produced by the operation will be preserved, otherwise they are masked.
- i: deprecated at version 3.0.0
Use the inplace parameter instead.
- f:
- Returns
Examples
>>> d.Units <Units: radians> >>> print(d.array) [[ 0. 1.57079633] [ 3.14159265 4.71238898]] >>> import numpy >>> e = d.func(numpy.cos) >>> e.Units <Units: 1> >>> print(e.array) [[ 1.0 0.0] [-1.0 0.0]] >>> d.func(numpy.sin, inplace=True) >>> print(d.array) [[0.0 1.0] [0.0 -1.0]]
>>> d = cf.Data([-2, -1, 1, 2], mask=[0, 0, 0, 1]) >>> f = d.func(numpy.arctanh, preserve_invalid=True) >>> f.array masked_array(data=[nan, -inf, inf, --], mask=[False, False, False, True], fill_value=1e+20) >>> e = d.func(numpy.arctanh) # default preserve_invalid is False >>> e.array masked_array(data=[--, --, --, --], mask=[ True, True, True, True], fill_value=1e+20, dtype=float64)