w3resource

NumPy logic functions: logical_or() function

numpy.logical_or() function

The logical_or() function is used to compute the truth value of x1 OR x2 element-wise.

Syntax:

numpy.logical_or(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'logical_or'>

Version: 1.15.0

Parameter:

Name Description Required /
Optional
x1, x2 Logical OR is applied to the elements of x1 and x2.
They have to be of the same shape.
array_like
Required
out 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.
ndarray, None, or tuple of ndarray and None
Optional
where Values of True indicate to calculate the ufunc at that position,
values of False indicate to leave the value in the output alone.
array_like
Optional
**kwargs For other keyword-only arguments Required

Returns:
y : ndarray or bool - Boolean result with the same shape as x1 and x2 of the logical OR operation on elements of x1 and x2.
This is a scalar if both x1 and x2 are scalars.

NumPy.logical_or() method Example-1:

>>> import numpy as np
>>> np.logical_or(True, False)

Output:

True

NumPy.logical_or() method Example-2:

>>> import numpy as np
>>> np.logical_or([True, False], [False, False])

Output:

array([ True, False])

NumPy.logical_or() method Example-3:

>>> import numpy as np
>>> x = np.arange(7)
>>> np.logical_or(x < 2, x > 4)

Output:

array([ True,  True, False, False, False,  True,  True])

Python - NumPy Code Editor:

Previous: logical_and() function
Next: logical_not() function



Follow us on Facebook and Twitter for latest update.