Skip to content
fn

absolute

→Tensor
absolute(input: Tensor)

Element-wise absolute value.

Verbose alias of lucid.abs, exposed for parity with reference frameworks that publish both abs and absolute spellings of the same operation.

Parameters

inputTensor
Input tensor. Any numeric dtype.

Returns

Tensor

Tensor of the same shape and dtype as input containing ∣xi∣|x_i| element-wise.

Notes

Mathematical definition:

outi=∣xi∣\text{out}_i = |x_i|

The gradient is sign⁡(xi)\operatorname{sign}(x_i); the sub-gradient at xi=0x_i = 0 is conventionally taken to be 0.

Examples

>>> import lucid
>>> x = lucid.tensor([-1.5, 0.0, 2.0])
>>> lucid.absolute(x)
tensor([1.5, 0., 2.])