NumPy. Logical_ or() in Python

Truth values between x1 and x2 elementwise are computed using the NumPy. Logical or() technique. The logical OR function returns true when at least one input is true. It is denoted mathematically by the letter v. A truth table for the OR operation between p, and q is provided here.

pqp or q
TTT
TFT
FTT
FFF

Syntax:

Parameters:

  • x1 ,x2: These array-like objects, designated by the letters x1, and x2, are used to perform logical OR between input values. If the dimensions of x1 and x2 do not match, they are broadcast to a common shape.
  • Out: These are places in memory where the outcomes are kept. It could be a tuple of Ndarrays, a Ndarray, or None.
  • Where: The out array is set to fun when a location changes from false to true.
  • Casting: The object casting will be the same as that of a float32 or float64 because its default value is "same kind."
  • **Kwargs: More argument values are described as keywords under **kwargs.

Get back value:

When both x1 and x2 are boolean values, this function returns a single boolean value. It returns a broadcasted boolean Ndarray when both x1 and x2 are boolean Ndarrays.

Explanation

In the code snippet, lines 4, 6, and 11 will be used to assess the logical OR between two scalar values, two boolean arrays, and two logical conditions.

Output:

x1 v x2 between boolean values: T
x1 v x2 between boolean arrays: [ T  T  T F  T ]
x1 v x2 between conditions: [ T F F F T T T ]

Code 1: Active

Output:

Output Array :  [ T  T  T  T]

Code 2: If the input arrays have different forms, the Value Error

Output:

Value Error: operands could not be broadcast together with shapes (4,) (5,)