logical_xor() method in NumPy is used to perform the element-wise logical exclusive OR operation. It returns a single boolean value or boolean
The return value of a XOR operation is
True between two values A and B when both input values are different. Otherwise, it returns
False. Let's look at the truth table for XOR on two input values:
numpy.logical_xor(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True)
x1, x2: Array-like objects are used to apply
x2dimensions are not alike, they are broadcast to a standard shape.
out: This is the location in memory used to store results. It can be
ndarrayor a tuple of
where: When a location becomes true, the
outarray is set to
casting: The default value for this is
same_kind, meaning that object casting will be the same as
**kwargs: These are the keyword arguments.
It returns a single boolean value or
ndarray of boolean type.
In the code snippet below, we discuss different scenarios of the
logical_xor() function where
x2 can be either single boolean values or part of a boolean array. These values can be conditions where results are computed based on whether they're
# import numpy library in program import numpy as np # invoking logical xor on two boolean values print("x1 & x2 as boolean values: ", np.logical_xor(True, False)) # invoking logical xor on two boolean arrays print("x1 & x2 as boolean arrays: ", np.logical_xor([True, True, False, False], [True, False, True, False])) # creating a numpy array from 0 to 10 x = np.arange(10) # print logical_xor() results print("x1 & x2 are conditions: ", np.logical_xor(x < 1, x > 3))
np.logical_xor()with arrays as arguments.
np.logical_xor(). It returns a boolean array where each element of an array
xsatisfies the inequality
x < 1and
x > 3.
View all Courses