📜  Python中的 numpy.logical_not()(1)

📅  最后修改于: 2023-12-03 14:46:36.220000             🧑  作者: Mango

numpy.logical_not() in Python

The numpy.logical_not() function is a part of the numpy module in Python. It returns an array containing the element-wise logical NOT of the input array. For a given element, if it is zero or False, the output would be True, else it would be False.

Syntax:

numpy.logical_not(array)
Parameters
  • array: A numpy array containing elements to be evaluated for logical NOT.
Return Value
  • It returns an array containing the element-wise logical NOT of the input array.
Example Usage
import numpy as np

arr = np.array([True, False, 0, 1, 3, -1])
result = np.logical_not(arr)

print(result)

Output:

[False  True  True False False False]

In the above example, the input array arr contains a mix of boolean, integer and float values. When passed through the np.logical_not() function, we get an array containing the logical NOT of each element in the input array.

  • The first element in the input array is True, which when evaluated using logical NOT, results in False.
  • The second element in the input array is False, which when evaluated using logical NOT, results in True.
  • The third element in the input array is 0, which when evaluated using logical NOT, results in True.
  • The fourth element in the input array is 1, which when evaluated using logical NOT, results in False.
  • The fifth element in the input array is 3, which when evaluated using logical NOT, results in False.
  • The sixth element in the input array is -1, which when evaluated using logical NOT, results in False.

Therefore, the final output array returned by np.logical_not() contains [False True True False False False].