Cos#
- class deeptrack.elementwise.Cos(feature: Feature | None = None, **kwargs: Any)#
Bases:
ElementwiseFeatureApply the cosine function elementwise.
This feature applies xp.cos to each element in a NumPy array or a PyTorch tensor. It supports both direct input and pipeline composition.
Parameters#
- feature: Feature | None, optional
The input feature to which the cosine 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 Cos
Use with NumPy directly:
>>> import numpy as np >>> >>> result = Cos()(np.array([0, np.pi / 2, np.pi])) >>> result array([ 1.000000e+00, 6.123234e-17, -1.000000e+00])
Use with PyTorch directly:
>>> import torch >>> >>> result = Cos()(torch.tensor([0, torch.pi / 2, torch.pi])) >>> result tensor([ 1.0000e+00, -4.3711e-08, -1.0000e+00])
Use in a pipeline with a NumPy value:
>>> value = dt.Value(value=np.array([0, np.pi / 2, np.pi])) >>> pipeline = value >> Cos() >>> result = pipeline() >>> result array([ 1.000000e+00, 6.123234e-17, -1.000000e+00])
Use in a pipeline with a PyTorch value:
>>> value = dt.Value(value=torch.tensor([0, torch.pi / 2, torch.pi])) >>> pipeline = value >> Cos() >>> result = pipeline() >>> result tensor([ 1.0000e+00, -4.3711e-08, -1.0000e+00])
These are equivalent to:
>>> pipeline = Cos(value)