numpy.logical_not() in Python (original) (raw)
Last Updated : 29 Nov, 2018
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 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 NOT arr (element-wise).
Code 1 : Working
import
numpy as np
arr1
=
[
1
,
3
,
False
,
4
]
arr2
=
[
3
,
0
,
True
,
False
]
out_arr1
=
np.logical_not(arr1)
out_arr2
=
np.logical_not(arr2)
print
(
"Output Array 1 : "
, out_arr1)
print
(
"Output Array 2 : "
, out_arr2)
Output :
Output Array 1 : [False False True False] Output Array 2 : [False True False True]
Code 2 : Can check condition
import
numpy as np
arr1
=
np.arange(
8
)
print
(
"Output : \n"
, arr1
/
4
)
out_arr1
=
np.logical_not(arr1
/
4
=
=
0
)
print
(
"\n Boolean Output : \n"
, out_arr1)
Output :
Output : [ 0. 0.25 0.5 0.75 1. 1.25 1.5 1.75]
Boolean Output : [False True True True True True True True]
References :
https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.logical_not.html#numpy.logical_not
.
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_and() in Python 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_lik 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.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.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.isrealobj() in Python numpy.isrealobj(array) : This logical function helps to checks if the array has no complex type or array has a complex number. Even if imaginary part is equal to zero, it is not considered to be a Real Object. Parameters : array : [array_like]Input array or object whose elements, we need to test. Re 1 min read
- numpy.nonzero() in Python numpy.nonzero()function is used to Compute the indices of the elements that are non-zero. It returns a tuple of arrays, one for each dimension of arr, containing the indices of the non-zero elements in that dimension. The corresponding non-zero values in the array can be obtained with arr[nonzero(ar 2 min read
- numpy.isneginf() in Python The numpy.isneginf() function tests element-wise whether it is negative infinity or not, and returns the result as a boolean array. Syntax : numpy.isneginf(array, y = None) Parameters : array : [array_like]Input array or object whose elements, we need to test for infinity. y : [array_like]A boolean 2 min read
- numpy.isposinf() in Python The numpy.isposinf() function tests element-wise whether it is positive infinity or not and returns the result as a boolean array. Syntax : numpy.isposinf(array, y = None) Parameters: array : [array_like]Input array or object whose elements, we need to test for infinity. y : [array_like]A boolean ar 2 min read
- numpy.isinf() in Python The numpy.isinf() function tests element-wise whether it is +ve or -ve infinity or not return the result as a boolean array. Syntax: numpy.isinf(array [, out]) Parameters : array : [array_like]Input array or object whose elements, we need to test for infinity out : [ndarray, optional]Output array pl 2 min read