- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- 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 truth value of an array XOR another array element-wise in Numpy

To compute the truth value of an array XOR another array element-wise, use the **numpy.logical_xor()** method in Python Numpy. Return value is either True or False. Return value is the Boolean result of the logical XOR operation applied to the elements of x1 and x2; the shape is determined by broadcasting. This is a scalar if both x1 and x2 are scalars.

The out is 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.

## Steps

At first, import the required library −

import numpy as np

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

arr1 = np.array([[True, False, False],[False, True, True]]) arr2 = np.array([[True, False, True],[True, True, False]])

Display the arrays −

print("Array 1...

", arr1) print("

Array 2...

", arr2)

Get the type of the arrays −

print("

Our Array 1 type...

", arr1.dtype) print("

Our Array 2 type...

", arr2.dtype)

Get the dimensions of the Arrays −

print("

Our Array 1 Dimensions...

",arr1.ndim) print("

Our Array 2 Dimensions...

",arr2.ndim)

Get the shape of the Arrays −

print("

Our Array 1 Shape...

",arr1.shape) print("

Our Array 2 Shape...

",arr2.shape)

To compute the truth value of an array XOR another array element-wise, use the numpy.logical_xor() method. Return value is either True or False −

print("

Result (XOR)...

",np.logical_xor(arr1, arr2))

## Example

import numpy as np # Creating two 2D numpy array using the array() method # We have inserted elements arr1 = np.array([[True, False, False],[False, True, True]]) arr2 = np.array([[True, False, True], [True, True, False]]) # Display the arrays print("Array 1...

", arr1) print("

Array 2...

", arr2) # Get the type of the arrays print("

Our Array 1 type...

", arr1.dtype) print("

Our Array 2 type...

", arr2.dtype) # Get the dimensions of the Arrays print("

Our Array 1 Dimensions...

",arr1.ndim) print("

Our Array 2 Dimensions...

",arr2.ndim) # Get the shape of the Arrays print("

Our Array 1 Shape...

",arr1.shape) print("

Our Array 2 Shape...

",arr2.shape) # To compute the truth value of an array XOR another array elementwise, use the numpy.logical_xor() method in Python Numpy # Return value is either True or False print("

Result (XOR)...

",np.logical_xor(arr1, arr2))

## Output

Array 1... [[ True False False] [False True True]] Array 2... [[ True False True] [ True True False]] Our Array 1 type... bool Our Array 2 type... bool Our Array 1 Dimensions... 2 Our Array 2 Dimensions... 2 Our Array 1 Shape... (2, 3) Our Array 2 Shape... (2, 3) Result (XOR)... [[False False True] [ True False True]]

- Related Articles
- Compute the truth value of an array XOR another array element-wise based on conditions in Numpy
- Compute the truth value of an array AND to another array element-wise in Numpy
- Compute the truth value of an array OR to another array element-wise in Numpy
- Compute the truth value of NOT an array element-wise in Numpy
- Compute the truth value of an array AND to another array element-wise based on conditions in Numpy
- Compute the truth value of an array OR to another array element-wise based on conditions in Numpy
- Return the truth value of an array less than another element-wise in Numpy
- Return the truth value of an array equal to another element-wise in Numpy
- Return the truth value of an array greater than another element-wise in Numpy
- Compute the truth value of NOT an array element-wise based on conditions in Numpy
- Return the truth value of an array not equal to another element-wise in Numpy
- Return the truth value of an array less than equal to another element-wise in Numpy
- Return the truth value of an array greater than equal to another element-wise in Numpy
- Compute the bit-wise NOT of an array element-wise in Numpy
- Compute the bit-wise XOR of a 1D and a 2D array element-wise in Numpy