w3resource

NumPy Binary operations: bitwise_or() function

numpy.bitwise_or() function

The bitwise_or() function is used to compute the bit-wise OR of two arrays element-wise.

Version: 1.15.0

Syntax:

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

Parameter:

Name Description Required /
Optional
x1,x2 Only integer and boolean types are handled. 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. 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. Optional
**kwargs For other keyword-only arguments.

Return value:
out: [ndarray or scalar]
Result: This is a scalar if both x1 and x2 are scalars.

Example-1: numpy.bitwise_or() function

>>> import numpy as np
>>> np.bitwise_or(34, 4)
38
>>> np.bitwise_or([34, 4], 3)
array([35,  7])
>>> np.bitwise_or([34, 4], [2, 3])
array([34,  7])

Example-2: numpy.bitwise_or() function

>>> import numpy as np
>>> np.bitwise_or(np.array([2, 3, 256]), np.array([3, 3, 3]))
array([  3,   3, 259])
>>> np.array([2, 3, 256]) | np.array([3, 3, 3])
array([  3,   3, 259])
>>> np.bitwise_or([True, True], [False, True])
array([ True,  True], dtype=bool)

Python Code Editor:

Previous: bitwise_and()
Next: bitwise_xor()