Tanh#
- class deeptrack.elementwise.Tanh(feature: Feature | None = None, **kwargs: Any)#
Bases:
ElementwiseFeatureApply the hyperbolic tangent function elementwise.
This feature applies xp.tanh 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 hyperbolic tangent 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 Tanh
Use with NumPy directly:
>>> import numpy as np >>> >>> result = Tanh()(np.array([-1.0, 0.0, 1.0])) >>> result array([-0.76159416, 0. , 0.76159416])
Use with PyTorch directly:
>>> import torch >>> >>> result = Tanh()(torch.tensor([-1.0, 0.0, 1.0])) >>> result tensor([-0.7616, 0.0000, 0.7616])
Use in a pipeline with a NumPy value:
>>> value = dt.Value(value=np.array([-1.0, 0.0, 1.0])) >>> pipeline = value >> Tanh() >>> result = pipeline() >>> result array([-0.76159416, 0. , 0.76159416])
Use in a pipeline with a PyTorch value:
>>> value = dt.Value(value=torch.tensor([-1.0, 0.0, 1.0])) >>> pipeline = value >> Tanh() >>> result = pipeline() >>> result tensor([-0.7616, 0.0000, 0.7616])
These are equivalent to:
>>> pipeline = Tanh(value)