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

To compute the truth value of NOT an array element-wise, use the **numpy.logical_not()** method in Python Numpy. Return value is either True or False.

Return value is the boolean result with the same shape as x of the NOT operation on elements of x. This is a scalar if x is a scalar. 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.

NumPy offers comprehensive mathematical functions, random number generators, linear algebra routines, Fourier transforms, and more. It supports a wide range of hardware and computing platforms, and plays well with distributed, GPU, and sparse array libraries.

## Steps

At first, import the required library −

import numpy as np

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

arr = np.array([[True, False, True], [True, True, False]])

Display the array −

print("Array...\n", arr)

Get the type of the array −

print("\nOur Array type...\n", arr.dtype)

Get the dimension of the array −

print("\nOur Array Dimension...\n",arr.ndim)

Get the shape of the array −

print("\nOur Array Shape...\n",arr.shape)

To compute the truth value of NOT an array element-wise, use the numpy.logical_not() method in Python Numpy. Return value is either True or False −

print("\nResult (NOT)...\n",np.logical_not(arr))

## Example

import numpy as np # Creating a 2D numpy array using the array() method # We have inserted elements arr = np.array([[True, False, True], [True, True, False]]) # Display the array print("Array...\n", arr) # Get the type of the array print("\nOur Array type...\n", arr.dtype) # Get the dimension of the array print("\nOur Array Dimension...\n",arr.ndim) # Get the shape of the array print("\nOur Array Shape...\n",arr.shape) # To compute the truth value of NOT an array element-wise, use the numpy.logical_not() method in Python Numpy # Return value is either True or False print("\nResult (NOT)...\n",np.logical_not(arr))

## Output

Array... [[ True False True] [ True True False]] Our Array type... bool Our Array Dimension... 2 Our Array Shape... (2, 3) Result (NOT)... [[False True False] [False False True]]

- Related Questions & Answers
- Compute the truth value of NOT an array element-wise based on conditions in Numpy
- Compute the truth value of an array XOR another array element-wise 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 bit-wise NOT of an array element-wise in Numpy
- Compute the truth value of an array XOR another array element-wise based on conditions in Numpy
- Return the truth value of an array not equal to another 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 equal to another element-wise in Numpy
- Return the truth value of an array greater than another element-wise in Numpy
- Return the truth value of an array less than another element-wise in Numpy
- Compute the bit-wise NOT of a One-Dimensional array element-wise in Numpy
- Compute the bit-wise NOT of a Two-Dimensional array element-wise in Numpy
- Return the truth value of an array less than equal to another element-wise in Numpy