Skip to content
fn

relu

→Tensor
relu(input: Tensor)

Implementing kernel

C++ engine symbols that back this Python API.

Element-wise rectified linear unit.

Returns the positive part of each entry, zeroing out negatives.

Parameters

inputTensor
Input tensor.

Returns

Tensor

Element-wise result with the same shape as input.

Notes

Mathematical definition:

outi=max⁡(0,inputi)\text{out}_i = \max(0, \text{input}_i)

Sub-gradient at x=0x = 0 is conventionally taken as zero. Standard activation in CNNs / MLPs.

Examples

>>> import lucid
>>> x = lucid.tensor([1.0, 2.0, 3.0])
>>> lucid.relu(x)
Tensor([...])