fn

bitwise_and

Tensor
bitwise_and(input: Tensor, other: Tensor | Scalar)
source

Element-wise bitwise AND.

Element-wise bitwise operation on integer (or boolean) operands. For boolean inputs this reduces to the corresponding logical operation. Floating-point inputs are not supported and will raise.

Parameters

inputTensor
Left operand. Must have integer or boolean dtype.
otherTensor or scalar
Right operand. Must have integer or boolean dtype. Broadcasts against input.

Returns

Tensor

Tensor with shape broadcast(input.shape, other.shape) and dtype given by the usual integer type-promotion rules.

Notes

Bit-level definition (for each bit position k of every element):

outi[k]=inputi[k]otheri[k]\text{out}_i[k] = \text{input}_i[k] \land \text{other}_i[k]

For boolean tensors this is the same as logical_and. Bitwise operations are not differentiable; gradients are dropped.

Examples

>>> import lucid
>>> a = lucid.tensor([0b1100, 0b1010], dtype=lucid.int32)
>>> b = lucid.tensor([0b1010, 0b0110], dtype=lucid.int32)
>>> lucid.bitwise_and(a, b)
Tensor([...])