Square#
- class deeptrack.elementwise.Square(feature: Feature | None = None, **kwargs: Any)#
Bases:
ElementwiseFeatureApply the square function elementwise.
This feature applies xp.square to each element in a NumPy array or a PyTorch tensor. It supports both direct input and pipeline composition.
This operation computes x ** 2 for each element.
Parameters#
- feature: Feature | None, optional
The input feature to which the square 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 Square
Use with NumPy directly:
>>> import numpy as np >>> result = Square()(np.array([-2.0, 0.0, 3.0])) >>> result array([4., 0., 9.])
Use with PyTorch directly:
>>> import torch >>> result = Square()(torch.tensor([-2.0, 0.0, 3.0])) >>> result tensor([4., 0., 9.])
Use in a pipeline with a NumPy value:
>>> value = dt.Value(value=np.array([-2.0, 0.0, 3.0])) >>> pipeline = value >> Square() >>> result = pipeline() >>> result array([4., 0., 9.])
Use in a pipeline with a PyTorch value:
>>> value = dt.Value(value=torch.tensor([-2.0, 0.0, 3.0])) >>> pipeline = value >> Square() >>> result = pipeline() >>> result tensor([4., 0., 9.])
These are equivalent to:
>>> pipeline = Square(value)