NumPy Logic functions: logical_and() function
numpy.logical_and() function
The logical_and() function is used to compute the truth value of x1 AND x2 element-wise.
Syntax:
numpy.logical_and(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'logical_and'>
Version: 1.15.0
Parameter:
Name | Description | Required / Optional |
---|---|---|
x1, x2 | Input arrays. x1 and x2 must be of the same shape. array_like |
Required |
out | A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned. A tuple (possible only as a keyword argument) must have length equal to the number of outputs. ndarray, None, or tuple of ndarray and None |
Optional |
where | Values of True indicate to calculate the ufunc at that position, values of False indicate to leave the value in the output alone. array_like |
Optional |
**kwargs | For other keyword-only arguments | Required |
Returns:
y : ndarray or bool - Boolean result with the same shape as x1 and x2 of the logical AND operation on corresponding elements of x1 and x2.
This is a scalar if both x1 and x2 are scalars.
NumPy.logical_and() method Example-1:
>>> import numpy as np
>>> np.logical_and(True, False)
Output:
False
NumPy.logical_and() method Example-2:
>>> import numpy as np
>>> np.logical_and([True, False], [False, False])
Output:
array([False, False])
NumPy.logical_and() method Example-3:
>>> import numpy as np
>>> x = np.arange(6)
>>> np.logical_and(x>1, x<4)
Output:
array([False, False, True, True, False, False])
Python - NumPy Code Editor:
Previous: isscalar() function
Next: logical_or() function
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/numpy/logic-functions/logical_and.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics