- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Compute the bit-wise XOR of two Two-Dimensional arrays element-wise in Numpy

To compute the bit-wise XOR of two 2D arrays element-wise, use the **numpy.bitwise_xor()** method in Python Numpy. Computes the bit-wise XOR of the underlying binary representation of the integers in the input arrays. This ufunc implements the C/Python operator ^.

The 1^{st} and 2^{nd} parameter are the arrays, only integer and boolean types are handled. If x1.shape != x2.shape, they must be broadcastable to a common shape.

The where parameter is the condition broadcast over the input. At locations where the condition is True, the out array will be set to the ufunc result. Elsewhere, the out array will retain its original value. Note that if an uninitialized out array is created via the default out=None, locations within it where the condition is False will remain uninitialized.

## Steps

At first, import the required library −

import numpy as np

Creating two 2D numpy arrays using the array() method. We have inserted elements of int type −

arr1 = np.array([[34, 78, 47], [82, 69, 29]]) arr2 = np.array([[59, 98, 36], [81, 55, 32]])

Display the arrays −

print("Array 1...\n", arr1) print("\nArray 2...\n", arr2)

Get the type of the arrays −

print("\nOur Array 1 type...\n", arr1.dtype) print("\nOur Array 2 type...\n", arr2.dtype)

Get the dimensions of the Arrays −

print("\nOur Array 1 Dimensions...\n",arr1.ndim) print("\nOur Array 2 Dimensions...\n",arr2.ndim)

Get the shape of the Arrays −

print("\nOur Array 1 Shape...\n",arr1.shape) print("\nOur Array 2 Shape...\n",arr2.shape)

To compute the bit-wise XOR of two 2D arrays element-wise, use the numpy.bitwise_xor() method −

print("\nResult (bit-wise XOR)...\n",np.bitwise_xor(arr1, arr2))

## Example

import numpy as np # Creating two 2D numpy arrays using the array() method # We have inserted elements of int type arr1 = np.array([[34, 78, 47], [82, 69, 29]]) arr2 = np.array([[59, 98, 36], [81, 55, 32]]) # Display the arrays print("Array 1...\n", arr1) print("\nArray 2...\n", arr2) # Get the type of the arrays print("\nOur Array 1 type...\n", arr1.dtype) print("\nOur Array 2 type...\n", arr2.dtype) # Get the dimensions of the Arrays print("\nOur Array 1 Dimensions...\n",arr1.ndim) print("\nOur Array 2 Dimensions...\n",arr2.ndim) # Get the shape of the Arrays print("\nOur Array 1 Shape...\n",arr1.shape) print("\nOur Array 2 Shape...\n",arr2.shape) # To compute the bit-wise XOR of two arrays element-wise, use the numpy.bitwise_xor() method in Python Numpy print("\nResult (bit-wise XOR)...\n",np.bitwise_xor(arr1, arr2))

## Output

Array 1... [[34 78 47] [82 69 29]] Array 2... [[59 98 36] [81 55 32]] Our Array 1 type... int64 Our Array 2 type... int64 Our Array 1 Dimensions... 2 Our Array 2 Dimensions... 2 Our Array 1 Shape... (2, 3) Our Array 2 Shape... (2, 3) Result (bit-wise XOR)... [[ 25 44 11] [ 3 114 61]]

- Related Questions & Answers
- Compute the bit-wise XOR of two One-Dimensional Numpy arrays element-wise
- Compute the bit-wise XOR of two Numpy arrays element-wise
- Compute the bit-wise OR of two Two-Dimensional arrays element-wise in Numpy
- Compute the bit-wise AND of two Two-Dimensional arrays element-wise in Numpy
- Compute the bit-wise XOR of two boolean arrays element-wise in Numpy
- Compute the bit-wise AND of two One-Dimensional Numpy arrays element-wise
- Compute the bit-wise OR of two One-Dimensional Numpy arrays element-wise
- Compute the bit-wise OR of two Numpy arrays element-wise
- Compute the bit-wise AND of two arrays element-wise in Numpy
- Compute the bit-wise OR of two boolean arrays element-wise in Numpy
- Compute the bit-wise AND of two boolean arrays element-wise in Numpy
- Compute the bit-wise NOT of a Two-Dimensional array element-wise in Numpy
- Compute the bit-wise NOT of a One-Dimensional array element-wise in Numpy
- Compute the bit-wise XOR of a 1D and a 2D array element-wise in Numpy
- Compute the bit-wise AND of a One Dimensional and a zero-dimensional array element-wise in Numpy