mindspore.ops.logical_and
- mindspore.ops.logical_and(input, other)[source]
Computes the "logical AND" of two tensors element-wise.
Inputs of input and other comply with the implicit type conversion rules to make the data types consistent. The inputs must be two tensors or one tensor and one bool.
When the inputs are two tensors, the shapes of them could be broadcast.
When the inputs are one tensor and one bool, the bool object could only be a constant.
\[out_{i} = input_{i} \wedge other_{i}\]Note
logical_and supports broadcasting.
- Parameters
- Returns
Tensor, the shape is the same as the one after broadcasting, and the data type is bool.
- Raises
TypeError – If neither input nor other is a Tensor.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore >>> import numpy as np >>> from mindspore import Tensor, ops >>> x = Tensor(np.array([True, False, True]), mindspore.bool_) >>> y = Tensor(np.array([True, True, False]), mindspore.bool_) >>> output = ops.logical_and(x, y) >>> print(output) [ True False False] >>> x = Tensor(1, mindspore.bool_) >>> y = Tensor(0, mindspore.bool_) >>> output = ops.logical_and(x, y) >>> print(output) False >>> x = True >>> y = Tensor(0, mindspore.bool_) >>> output = ops.logical_and(x, y) >>> print(output) False >>> x = True >>> y = Tensor(np.array([True, False]), mindspore.bool_) >>> output = ops.logical_and(x, y) >>> print(output) [True False]