Real#
- class deeptrack.elementwise.Real(feature: Feature | None = None, **kwargs: Any)#
Bases:
ElementwiseFeatureApply the real-part function elementwise.
This feature applies xp.real to each element in a NumPy array or a PyTorch tensor. It supports both direct input and pipeline composition.
For real-valued inputs, it returns the input unchanged. For complex-valued inputs, it returns the real part.
Parameters#
- feature: Feature | None, optional
The input feature to which the real function will be applied. If None, the function is applied directly to the input array or tensor.
Examples#
>>> import deeptrack as dt >>> from deeptrack.elementwise import Real
Use with NumPy directly:
>>> import numpy as np >>> result = Real()(np.array([1+2j, 3+0j, -4.5])) >>> result array([ 1. , 3. , -4.5])
Use with PyTorch directly:
>>> import torch >>> result = Real()(torch.tensor([1+2j, 3+0j, -4.5+0j])) >>> result tensor([ 1.0000, 3.0000, -4.5000])
Use in a pipeline with a NumPy value:
>>> value = dt.Value(value=np.array([1+2j, 3+0j, -4.5])) >>> pipeline = value >> Real() >>> result = pipeline() >>> result array([ 1. , 3. , -4.5])
Use in a pipeline with a PyTorch value:
>>> value = dt.Value(value=torch.tensor([1+2j, 3+0j, -4.5+0j])) >>> pipeline = value >> Real() >>> result = pipeline() >>> result tensor([ 1.0000, 3.0000, -4.5000])
These are equivalent to:
>>> pipeline = Real(value)