Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

NumPy Binary operations: bitwise_xor() function

numpy.bitwise_xor() function

The bitwise_xor() function is used to compute the bit-wise XOR of two arrays element-wise.

Version: 1.15.0

Syntax:

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

Parameter:

Name Description Required /
Optional
x1,x2 Only integer and boolean types are handled. 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. 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. Optional
**kwargs For other keyword-only arguments.

Return value:
out: [ndarray or scalar]
Result. This is a scalar if both x1 and x2 are scalars.

Example-1: numpy.bitwise_xor() function

>>> import numpy as np
>>> np.bitwise_xor(12, 16)
28
>>> np.binary_repr(28)
'11100'

Example-2: numpy.bitwise_xor() function

>>> import numpy as np
>>> np.bitwise_xor(28, 5)
25
>>> np.bitwise_xor([28, 3], 7)
array([27,  4])

Example-3: numpy.bitwise_xor() function

import numpy as np
>>> np.bitwise_xor([31,3], [5,6])
array([26,  5])
>>> np.bitwise_xor([True, True],  [False, True])
array([ True, False], dtype=bool)

Python Code Editor:

Previous: bitwise_or()
Next: invert()