Skip to content
fn

logical_and

→Tensor
logical_and(input: Tensor, other: Tensor | Scalar)

Implementing kernel

C++ engine symbols that back this Python API.

Element-wise logical AND.

Element-wise boolean operation. Non-boolean inputs are first reduced to their truthiness (False iff the value is exactly zero) before the operation is applied. The output dtype is bool.

Parameters

inputTensor
Left operand (treated as boolean).
otherTensor or scalar
Right operand (treated as boolean). Broadcasts against input.

Returns

Tensor

Boolean tensor with shape broadcast(input.shape, other.shape).

Notes

Mathematical definition (with xˉ\bar x denoting boolean coercion):

outi=xˉi∧yˉi\text{out}_i = \bar{x}_i \land \bar{y}_i

Logical operations are not differentiable; gradients are dropped. Equivalent to input.bool() & other.bool().

Examples

>>> import lucid
>>> a = lucid.tensor([True, False, True])
>>> b = lucid.tensor([True, True, False])
>>> lucid.logical_and(a, b)
Tensor([...])