logical_not()
is used to compute the logical NOT of boolean argument values. The logical NOT performs a unary operation that inverts the input signal or values. Here, we have a truth table for the NOT gate.
numpy.logical_not(x,/,out=None,*,where=True,casting='same_kind',order='K',dtype=None,subok=True)
x
: It is an array-like object to which logical not will be applied.out
: It is a memory segment used to store results. It can be a simple ndarray
, a tuple of ndarray
, or None
.where
: When a location becomes True
, the out
array is set to ufunc
. In this case, ufunc
is used to return program output.casting
: Its default is same_kind
, which means object casting will be the same as float64
and float32
.**kwargs
: These are the additional keyword arguments.It either returns a boolean, scaler, or ndarray of boolean values.
In the given code snippet, we'll calculate the logical NOT on condition, scaler value, and logical array:
# importing numpy library as alias npimport numpy as np# generating an array from 0 to 5x = np.arange(5)# calculate logical NOT on x < 3print(np.logical_not(x<3))# calculating NOT on 10print(np.logical_not(10))# calculating NOT on numpy arrayprint(np.logical_not([True, False, 0, 1, 10, 20, 30]))