# megengine.functional.logical_and¶

logical_and(x, y)[源代码]

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$$.

• x – first input tensor. Should have a boolean data type.

• y – second input tensor. Must be compatible with $$x$$ (see 广播机制与规则 ). Should have a boolean data type.

a tensor containing the result of the element-wise logical AND operation. The returned tensor must have a data type of bool.

>>> 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 for F.logical_and on boolean tensors.

>>> x & y
Tensor([False False  True], dtype=bool, device=xpux:0)