Overview:
-
The numpy.logical_or() function applies logical OR between the elements of two numpy array-like instances. The logical OR operation returns True when one of the operands is True, else it returns False.
-
The numpy.bitwise_or() function is applied between the binary bits of the elements of two NumPy array-likes.
Truth table - OR operation:
Operand 1 | Operand 2 | Operand 1 OR Operand 2 |
---|---|---|
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 1 |
Example 1:
# Example Python program that applies # Populate ndarray with random zeros and ones # Creation of ndarrays populateNDArray(boolArray1) # Apply logical OR between array elements print("Boolean array1:") |
Output:
Boolean array1: [[0 0 0] [1 1 0] [1 1 0]] Boolean array2: [[1 0 1] [1 1 0] [1 0 1]] Array1 or array2: [[ True False True] [ True True False] [ True True True]] |
Example 2:
# Example Python program that does # The Python list is converted to ndarray internally # Apply logical OR # Print operands print(type(flags2)) # Print results |
Output:
<class 'list'> [1, 1, 0, 0, 0] <class 'list'> [1, 0, 1, 0, 1] <class 'numpy.ndarray'> [ True True True False True] |