Log#
- class deeptrack.elementwise.Log(feature: Feature | None = None, **kwargs: Any)#
Bases:
ElementwiseFeatureApply the natural logarithm function elementwise.
This feature applies xp.log to each element in a NumPy array or a PyTorch tensor. It supports both direct input and pipeline composition.
The input must be strictly positive. Passing zero or negative values will return -inf or NaN, and may raise warnings or errors depending on the backend.
Parameters#
- feature: Feature | None, optional
The input feature to which the natural logarithm 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 Log
Use with NumPy directly:
>>> import numpy as np >>> result = Log()(np.array([1.0, np.e, 10.0])) >>> result array([0. , 1. , 2.30258509])
Use with PyTorch directly:
>>> import torch >>> result = Log()(torch.tensor([1.0, torch.exp(torch.tensor(1.0)), 10.0])) >>> result tensor([0.0000, 1.0000, 2.3026])
Use in a pipeline with a NumPy value:
>>> value = dt.Value(value=np.array([1.0, np.e, 10.0])) >>> pipeline = value >> Log() >>> result = pipeline() >>> result array([0. , 1. , 2.30258509])
Use in a pipeline with a PyTorch value:
>>> value = dt.Value(value=torch.tensor( ... [1.0, torch.exp(torch.tensor(1.0)), 10.0]) ... ) >>> pipeline = value >> Log() >>> result = pipeline() >>> result tensor([0.0000, 1.0000, 2.3026])
These are equivalent to:
>>> pipeline = Log(value)