megengine.functional.logical_and¶
- logical_and(x, y)[source]¶
Element-wise logical AND.
Computes the logical AND for each element \(x_i\) of the input tensor \(x\) with the respective element \(y_i\) of the input tensor \(y\).
- Parameters
x – first input tensor. Should have a boolean data type.
y – second input tensor. Must be compatible with \(x\) (see Broadcasting mechanism and rules ). Should have a boolean data type.
- Returns
a tensor containing the result of the element-wise logical AND operation. The returned tensor must have a data type of
bool
.
See also
Examples
>>> F.logical_and(True, False) Tensor(False, dtype=bool, device=xpux:0)
Element-wise logical AND:
>>> x = Tensor([True, False, True]) >>> y = Tensor([False, False, True]) >>> F.logical_and(x, y) Tensor([False False True], dtype=bool, device=xpux:0)
The
&
operator can be used as a shorthand forF.logical_and
on boolean tensors.>>> x & y Tensor([False False True], dtype=bool, device=xpux:0)