numpy.logical_and() in Python (original) (raw)
Last Updated : 29 Nov, 2018
numpy.logical_and(arr1, arr2, out=None, where = True, casting = ‘same_kind’, order = ‘K’, dtype = None, ufunc ‘logical_and’) : This is a logical function and it helps user to find out the truth value of arr1 AND arr2 element-wise. Both the arrays must be of same shape.
Parameters :
arr1 : [array_like]Input array.
arr2 : [array_like]Input array.out : [ndarray, optional]Output array with same dimensions as Input array, placed with result.
**kwargs : allows you to pass keyword variable length of argument to a function. It is used when we want to handle named argument in a function.
where : [array_like, optional]True value means to calculate the universal functions(ufunc) at that position, False value means to leave the value in the output alone.
Return :
An array with Boolean results of arr1 and arr2 element-wise(of the same shape).
Code 1 : Working
import
numpy as np
arr1
=
[
1
,
3
,
False
,
4
]
arr2
=
[
3
,
0
,
True
,
False
]
out_arr
=
np.logical_and(arr1, arr2)
print
(
"Output Array : "
, out_arr)
Output :
Output Array : [ True False False False]
Code 2 : Value Error if input array’s have different shapes
import
numpy as np
arr1
=
[
8
,
2
,
False
,
4
]
arr2
=
[
3
,
0
,
True
,
False
,
8
]
out_arr
=
np.logical_and(arr1, arr2)
print
(
"Output Array : "
, out_arr)
Output :
**ValueError:**operands could not be broadcast together with shapes (4,) (5,)
References :
https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.logical_and.html#numpy.logical_and
.
Similar Reads
- numpy.logical_or() in Python numpy.logical_or(arr1, arr2, out=None, where = True, casting = 'same_kind', order = 'K', dtype = None, ufunc 'logical_or') : This is a logical function and it helps user to find out the truth value of arr1 OR arr2 element-wise. Both the arrays must be of same shape. Parameters : arr1 : [array_like]I 2 min read
- numpy.logical_not() in Python numpy.logical_not(arr, out=None, where = True, casting = 'same_kind', order = 'K', dtype = None, ufunc 'logical_not') : This is a logical function that computes the truth value of NOT arr element-wise. Parameters : arr1 : [array_like]Input array. out : [ndarray, optional]Output array with same dimen 2 min read
- numpy.logical_xor() in Python numpy.logical_xor(arr1, arr2, out=None, where = True, casting = 'same_kind', order = 'K', dtype = None, ufunc 'logical_xor') : This is a logical function and it helps user to find out the truth value of arr1 XOR arr2 element-wise. Both the arrays must be of same shape. Parameters : arr1 : [array_lik 2 min read
- numpy.any() in Python The numpy.any() function tests whether any array elements along the mentioned axis evaluate to True. Syntax : numpy.any(a, axis = None, out = None, keepdims = class numpy._globals._NoValue at 0x40ba726c) Parameters : array :[array_like]Input array or object whose elements, we need to test. axis : [i 3 min read
- numpy.isreal() in Python numpy.isreal(array) : Test element-wise whether it is a real number or not(not infinity or not Not a Number) and return the result as a boolean array. Parameters : array : [array_like] Input array whose element we want to test Return : boolean array containing the result Code 1 : Python Code # Pytho 2 min read
- numpy.isnan() in Python The numpy.isnan() function tests element-wise whether it is NaN or not and returns the result as a boolean array. Syntax : numpy.isnan(array [, out]) Parameters : array : [array_like]Input array or object whose elements, we need to test for infinity out : [ndarray, optional]Output array placed with 2 min read
- numpy.bitwise_and() in Python numpy.bitwise_and() function is used to Compute the bit-wise AND of two array element-wise. This function computes the bit-wise AND of the underlying binary representation of the integers in the input arrays. Syntax : numpy.bitwise_and(arr1, arr2, /, out=None, *, where=True, casting='same_kind', ord 2 min read
- numpy.all() in Python The numpy.all() function tests whether all array elements along the mentioned axis evaluate to True. Syntax: numpy.all(array, axis = None, out = None, keepdims = class numpy._globals._NoValue at 0x40ba726c) Parameters : array :[array_like]Input array or object whose elements, we need to test. axis : 3 min read
- Python | Decimal logical_and() method Decimal#logical_and() : logical_and() is a Decimal class method which returns the digit-wise and of the two (logical) Decimal values. Syntax: Decimal.logical_and() Parameter: Decimal values Return: the digit-wise and of the two (logical) Decimal values. Code #1 : Example for logical_and() method # P 2 min read
- numpy.not_equal() in Python The numpy.not_equal() checks whether two element are unequal or not. Syntax : numpy.not_equal(x1, x2[, out])Parameters : x1, x2 : [array_like]Input Array whose elements we want to checkout : [ndarray, optional]Output array that returns True/False. A placeholder the same shape as x1 to store the resu 2 min read