ArithmeticOperationFeature#
- class deeptrack.features.ArithmeticOperationFeature(op: Callable[[Any, Any], Any], b: Any | list[Any] | Callable[[...], Any | list[Any]] = 0, **kwargs: Any)#
Bases:
FeatureApply an arithmetic operation element-wise to the inputs.
This feature performs an arithmetic operation (e.g., addition, subtraction, multiplication) on the input data. The input can be a single value or a list of values.
If a list is passed, the operation is applied to each element.
If the inputs are lists of different lengths, the shorter list is cycled.
Parameters#
- op: Callable[[Any, Any], Any]
The arithmetic operation to apply, such as a built-in operator (e.g., operator.add, operator.mul) or a custom callable.
- b: Any or list[Any], optional
The second operand for the operation. Defaults to 0. If a list is provided, the operation will apply element-wise.
- **kwargs: Any
Additional keyword arguments passed to the parent Feature.
Attributes#
- __distributed__: bool
Set to False, indicating that this feature’s .get() method processes the entire input at once even if it is a list, rather than distributing calls for each item of the list.
Methods#
- get(a, b, **kwargs) -> list[Any]
Apply the arithmetic operation element-wise to the input data.
Examples#
>>> import deeptrack as dt
Define a simple addition operation:
>>> import operator >>> >>> addition = dt.ArithmeticOperationFeature(operator.add, b=10)
Create a list of input values:
>>> input_values = [1, 2, 3, 4]
Apply the operation:
>>> output_values = addition(input_values) >>> output_values [11, 12, 13, 14]
Methods Summary
get(a, b, **kwargs)Apply the operation element-wise to the input data.
Methods Documentation
- get(a: list[Any], b: Any | list[Any], **kwargs: Any) list[Any]#
Apply the operation element-wise to the input data.
Parameters#
- a: list[Any]
The input data, either a single value or a list of values, to be transformed by the arithmetic operation.
- b: Any or list[Any]
The second operand(s) for the operation. If a single value is provided, it is broadcast to match the input size. If a list is provided, it will be cycled to match the length of the input list.
- **kwargs: Any
Additional parameters or property overrides. These are generally unused in this context but provided for compatibility with the Feature interface.
Returns#
- list[Any]
A list containing the results of applying the operation to the input data element-wise.