flopscope.numpy.bitwise_or
fnp.bitwise_or(*args, **kwargs)[flopscope source][numpy source]
Compute the bit-wise OR of two arrays element-wise.
Adapted from NumPy docs np.bitwise_or
Element-wise bitwise OR.
Computes the bit-wise OR of the underlying binary representation of
the integers in the input arrays. This ufunc implements the C/Python
operator |.
Parameters
- x1, x2:array_like
Only integer and boolean types are handled. If
x1.shape != x2.shape, they must be broadcastable to a common shape (which becomes the shape of the output).- out:ndarray, None, or tuple of ndarray and None, optional
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.
- where:array_like, optional
This condition is broadcast over the input. At locations where the condition is True, the
outarray will be set to the ufunc result. Elsewhere, theoutarray will retain its original value. Note that if an uninitializedoutarray is created via the defaultout=None, locations within it where the condition is False will remain uninitialized.- **kwargs
For other keyword-only arguments, see the ufunc docs.
Returns
- out:ndarray or scalar
Result. This is a scalar if both
x1andx2are scalars.
See also
- we.flops.logical_or
- we.flops.bitwise_and
- we.flops.bitwise_xor
- binary_repr Return the binary representation of the input number as a string.
Examples
>>> import flopscope.numpy as fnpThe number 13 has the binary representation 00001101. Likewise,
16 is represented by 00010000. The bit-wise OR of 13 and 16 is
then 00011101, or 29:
>>> flops.bitwise_or(13, 16)
29
>>> flops.binary_repr(29)
'11101'>>> flops.bitwise_or(32, 2)
34
>>> flops.bitwise_or([33, 4], 1)
array([33, 5])
>>> flops.bitwise_or([33, 4], [1, 2])
array([33, 6])>>> flops.bitwise_or(flops.array([2, 5, 255]), flops.array([4, 4, 4]))
array([ 6, 5, 255])
>>> flops.array([2, 5, 255]) | flops.array([4, 4, 4])
array([ 6, 5, 255])
>>> flops.bitwise_or(flops.array([2, 5, 255, 2147483647], dtype=flops.int32),
... flops.array([4, 4, 4, 2147483647], dtype=flops.int32))
array([ 6, 5, 255, 2147483647], dtype=int32)
>>> flops.bitwise_or([True, True], [False, True])
array([ True, True])The | operator can be used as a shorthand for flops.bitwise_or on
ndarrays.
>>> x1 = flops.array([2, 5, 255])
>>> x2 = flops.array([4, 4, 4])
>>> x1 | x2
array([ 6, 5, 255])