w3resource

NumPy Logic functions: logical_xor() function

numpy.logical_xor() function

The logical_xor() function is used to compute the truth value of x1 XOR x2, element-wise.

Syntax:

numpy.logical_xor(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'logical_xor'>

Version: 1.15.0

Parameter:

Name Description Required /
Optional
x1, x2 Logical XOR is applied to the elements of x1 and x2.
They must be broadcastable to 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 : bool or ndarray of bool - Boolean result of the logical XOR operation applied to the elements of x1 and x2;
the shape is determined by whether or not broadcasting of one or both arrays was required. This is a scalar if both x1 and x2 are scalars.

NumPy.logical_xor() method Example-1:

>>> import numpy as np
>>> np.logical_xor(True, False)

Output:

True

NumPy.logical_xor() method Example-2:

>>> import numpy as np
>>> np.logical_xor([True, True, False, False], [True, False, True, False])

Output:

array([False,  True,  True, False])

NumPy.logical_xor() method Example-3:

>>> import numpy as np
>>> x = np.arange(6)
>>> np.logical_xor(x < 2, x > 5)

Output:

array([ True,  True, False, False, False, False])

Simple example showing support of broadcasting

NumPy.logical_xor() method Example-4:

>>> import numpy as np
>>> np.logical_xor(0, np.eye(3))

Output:

array([[ True, False, False],
       [False,  True, False],
       [False, False,  True]])

Python - NumPy Code Editor:

Previous: logical_not() function
Next: allclose() function



Become a Patron!

Follow us on Facebook and Twitter for latest update.

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://w3resource.com/numpy/logic-functions/logical_xor.php