Imag#

class deeptrack.elementwise.Imag(feature: Feature | None = None, **kwargs: Any)#

Bases: ElementwiseFeature

Apply the imaginary-part function elementwise.

This class handles real and complex inputs for both NumPy and PyTorch backends. For real inputs, it returns 0; for complex inputs, it extracts the imaginary part.

Parameters#

feature: Feature | None, optional

The input feature to which the imaginary-part function will be applied. If None, the function is applied directly to the input.

Examples#

>>> import deeptrack as dt
>>> from deeptrack.elementwise import Imag

Use with NumPy directly:

>>> import numpy as np
>>> result = Imag()(np.array([1+2j, 3+0j, -4.5]))
>>> result
array([ 2.,  0.,  0.])

Use with PyTorch directly:

>>> import torch
>>> result = Imag()(torch.tensor([1+2j, 3+0j, -4.5+0j]))
>>> result
tensor([2., 0., 0.])

Use in a pipeline with a NumPy value:

>>> value = dt.Value(value=np.array([1+2j, 3+0j, -4.5]))
>>> pipeline = value >> Imag()
>>> result = pipeline()
>>> result
array([ 2.,  0.,  0.])

Use in a pipeline with a PyTorch value:

>>> value = dt.Value(value=torch.tensor([1+2j, 3+0j, -4.5+0j]))
>>> pipeline = value >> Imag()
>>> result = pipeline()
>>> result
tensor([2., 0., 0.])

These are equivalent to:

>>> pipeline = Imag(value)