apply_along_da_axis#
- movement.utils.broadcasting.apply_along_da_axis(f, data, dimension, new_dimension_name=None)[source]#
Apply a function
facrossdimensionofdata.fshould be callable asf(input_1D)whereinput_1Dis a one-dimensionalnumpy.typing.ArrayLikeobject. It should return either a scalar or one-dimensionalnumpy.typing.ArrayLikeobject.- Parameters:
f (Callable) – Function that takes 1D inputs and returns either scalar or 1D outputs. This will be cast across the
dimensionof thedata.data (xarray.DataArray) – Values to be cast over.
dimension (str) – Dimension of
datato broadcastfacross.new_dimension_name (str, optional) – If
freturns non-scalar values, the dimension in the output that these values are returned along is given the namenew_dimension_name. Defaults to"result".
- Returns:
Result of broadcasting
falong thedimensionofdata.If
freturns a scalar or(1,)-shaped output, the output has one fewer dimension thandata, withdimensionbeing dropped. All other dimensions retain their names and sizes.If
freturns a(n,)-shaped output forn > 1; all non-dimensiondimensions ofdataretain their shapes. Thedimensiondimension itself is replaced with a new dimension,new_dimension_name, containing the output of the application off.
- Return type: