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[[TypeAliasType],TypeVar(ScalarOr1D,float,int,bool,TypeAliasType)]) – Function that takes 1D inputs and returns either scalar or 1D outputs. This will be cast across thedimensionof thedata.data (
DataArray) – Values to be cast over.dimension (
str) – Dimension ofdatato broadcastfacross.new_dimension_name (
str|None) – Iffreturns 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: