
- NumPy - Home
- NumPy - Introduction
- NumPy - Environment
- NumPy Arrays
- NumPy - Ndarray Object
- NumPy - Data Types
- NumPy Creating and Manipulating Arrays
- NumPy - Array Creation Routines
- NumPy - Array Manipulation
- NumPy - Array from Existing Data
- NumPy - Array From Numerical Ranges
- NumPy - Iterating Over Array
- NumPy - Reshaping Arrays
- NumPy - Concatenating Arrays
- NumPy - Stacking Arrays
- NumPy - Splitting Arrays
- NumPy - Flattening Arrays
- NumPy - Transposing Arrays
- NumPy Indexing & Slicing
- NumPy - Indexing & Slicing
- NumPy - Indexing
- NumPy - Slicing
- NumPy - Advanced Indexing
- NumPy - Fancy Indexing
- NumPy - Field Access
- NumPy - Slicing with Boolean Arrays
- NumPy Array Attributes & Operations
- NumPy - Array Attributes
- NumPy - Array Shape
- NumPy - Array Size
- NumPy - Array Strides
- NumPy - Array Itemsize
- NumPy - Broadcasting
- NumPy - Arithmetic Operations
- NumPy - Array Addition
- NumPy - Array Subtraction
- NumPy - Array Multiplication
- NumPy - Array Division
- NumPy Advanced Array Operations
- NumPy - Swapping Axes of Arrays
- NumPy - Byte Swapping
- NumPy - Copies & Views
- NumPy - Element-wise Array Comparisons
- NumPy - Filtering Arrays
- NumPy - Joining Arrays
- NumPy - Sort, Search & Counting Functions
- NumPy - Searching Arrays
- NumPy - Union of Arrays
- NumPy - Finding Unique Rows
- NumPy - Creating Datetime Arrays
- NumPy - Binary Operators
- NumPy - String Functions
- NumPy - Matrix Library
- NumPy - Linear Algebra
- NumPy - Matplotlib
- NumPy - Histogram Using Matplotlib
- NumPy Sorting and Advanced Manipulation
- NumPy - Sorting Arrays
- NumPy - Sorting along an axis
- NumPy - Sorting with Fancy Indexing
- NumPy - Structured Arrays
- NumPy - Creating Structured Arrays
- NumPy - Manipulating Structured Arrays
- NumPy - Record Arrays
- Numpy - Loading Arrays
- Numpy - Saving Arrays
- NumPy - Append Values to an Array
- NumPy - Swap Columns of Array
- NumPy - Insert Axes to an Array
- NumPy Handling Missing Data
- NumPy - Handling Missing Data
- NumPy - Identifying Missing Values
- NumPy - Removing Missing Data
- NumPy - Imputing Missing Data
- NumPy Performance Optimization
- NumPy - Performance Optimization with Arrays
- NumPy - Vectorization with Arrays
- NumPy - Memory Layout of Arrays
- Numpy Linear Algebra
- NumPy - Linear Algebra
- NumPy - Matrix Library
- NumPy - Matrix Addition
- NumPy - Matrix Subtraction
- NumPy - Matrix Multiplication
- NumPy - Element-wise Matrix Operations
- NumPy - Dot Product
- NumPy - Matrix Inversion
- NumPy - Determinant Calculation
- NumPy - Eigenvalues
- NumPy - Eigenvectors
- NumPy - Singular Value Decomposition
- NumPy - Solving Linear Equations
- NumPy - Matrix Norms
- NumPy Element-wise Matrix Operations
- NumPy - Sum
- NumPy - Mean
- NumPy - Median
- NumPy - Min
- NumPy - Max
- NumPy Set Operations
- NumPy - Unique Elements
- NumPy - Intersection
- NumPy - Union
- NumPy - Difference
- NumPy Random Number Generation
- NumPy - Random Generator
- NumPy - Permutations & Shuffling
- NumPy - Uniform distribution
- NumPy - Normal distribution
- NumPy - Binomial distribution
- NumPy - Poisson distribution
- NumPy - Exponential distribution
- NumPy - Rayleigh Distribution
- NumPy - Logistic Distribution
- NumPy - Pareto Distribution
- NumPy - Visualize Distributions With Sea born
- NumPy - Matplotlib
- NumPy - Multinomial Distribution
- NumPy - Chi Square Distribution
- NumPy - Zipf Distribution
- NumPy File Input & Output
- NumPy - I/O with NumPy
- NumPy - Reading Data from Files
- NumPy - Writing Data to Files
- NumPy - File Formats Supported
- NumPy Mathematical Functions
- NumPy - Mathematical Functions
- NumPy - Trigonometric functions
- NumPy - Exponential Functions
- NumPy - Logarithmic Functions
- NumPy - Hyperbolic functions
- NumPy - Rounding functions
- NumPy Fourier Transforms
- NumPy - Discrete Fourier Transform (DFT)
- NumPy - Fast Fourier Transform (FFT)
- NumPy - Inverse Fourier Transform
- NumPy - Fourier Series and Transforms
- NumPy - Signal Processing Applications
- NumPy - Convolution
- NumPy Polynomials
- NumPy - Polynomial Representation
- NumPy - Polynomial Operations
- NumPy - Finding Roots of Polynomials
- NumPy - Evaluating Polynomials
- NumPy Statistics
- NumPy - Statistical Functions
- NumPy - Descriptive Statistics
- NumPy Datetime
- NumPy - Basics of Date and Time
- NumPy - Representing Date & Time
- NumPy - Date & Time Arithmetic
- NumPy - Indexing with Datetime
- NumPy - Time Zone Handling
- NumPy - Time Series Analysis
- NumPy - Working with Time Deltas
- NumPy - Handling Leap Seconds
- NumPy - Vectorized Operations with Datetimes
- NumPy ufunc
- NumPy - ufunc Introduction
- NumPy - Creating Universal Functions (ufunc)
- NumPy - Arithmetic Universal Function (ufunc)
- NumPy - Rounding Decimal ufunc
- NumPy - Logarithmic Universal Function (ufunc)
- NumPy - Summation Universal Function (ufunc)
- NumPy - Product Universal Function (ufunc)
- NumPy - Difference Universal Function (ufunc)
- NumPy - Finding LCM with ufunc
- NumPy - ufunc Finding GCD
- NumPy - ufunc Trigonometric
- NumPy - Hyperbolic ufunc
- NumPy - Set Operations ufunc
- NumPy Useful Resources
- NumPy - Quick Guide
- NumPy - Cheatsheet
- NumPy - Useful Resources
- NumPy - Discussion
- NumPy Compiler
Numpy bitwise_or() Function
The Numpy bitwise_or() function performs element-wise bitwise OR operation between two arrays or between an array and a scalar. Each bit of the output is set to 1 if at least one of the corresponding bits of the input operands is 1.
The arrays must have the same shape or be broadcastable to a common shape. This function is commonly used in scenarios requiring bit-level manipulation such as image processing or binary masking.
The result is a new array containing the bitwise OR of the input array's elements with the same shape and dtype as the input arrays. Below are the results of bitwise OR operation of bit combinations 1 and 0 −
- Bitwise AND of 0 and 0: 0
- Bitwise AND of 0 and 1: 1
- Bitwise AND of 1 and 0: 1
- Bitwise AND of 1 and 1: 1
Syntax
Following is the syntax of the Numpy bitwise_or() function −
numpy.bitwise_or(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
- x1, x2 (like an array): These arrays used for input to compute the element-wise bitwise OR for these arrays.
- out(Optional): This is the directory where the outcome is kept. It needs to have a shape that the inputs broadcast to, if one is given. A newly-allocated array is returned if it is not supplied.
-
where(Optional): Broadcast over the input is this condition. The ufunc result will be set to the
out
array at locations where the condition is True. If not, the initial value of theout
array will be maintained. -
casting(Optional): This parameter determines the type of data casting that is permitted.
'same_kind'
is the default value. -
order(Optional): Regulates the result's memory layout order. Returns
'K'
by default. - dtype(Optional): This parameter overrides the dtype of the result.
- subok(Optional): If True, sub-classes will be passed through. If False, the result will be a base-class array.
- signature(Optional): This parameter is used for more advanced ufunc signature support.
Return value
This function returns the array with the result of bitwise OR operation.
Example 1
Following is the basic example of Numpy bitwise_or() function in which shows the bitwise OR operation of two integer values −
import numpy as np a, b = 13, 17 print('Binary equivalents of 13 and 17:') print(bin(a), bin(b)) print('Bitwise OR of 13 and 17:') print(np.bitwise_or(a, b))
Its output is as follows −
Binary equivalents of 13 and 17: 0b1101 0b10001 Bitwise OR of 13 and 17: 29
Example 2
Here in this example we are using the bitwise_or() function to perform the bitwise OR operation element-wise between the two arrays −
import numpy as np # Define two NumPy arrays arr1 = np.array([10, 20, 30]) arr2 = np.array([1, 2, 3]) # Perform the bitwise OR operation result = np.bitwise_or(arr1, arr2) # Print the result print("Array 1:", arr1) print("Array 2:", arr2) print("Bitwise OR result:", result)
Below is the output of bitwise OR operation performed on two arrays −
Array 1: [10 20 30] Array 2: [1 2 3] Bitwise OR result: [11 22 31]
Example 3
Broadcasting in NumPy allows for the element-wise operations on arrays of different shapes by aligning them to a common shape. Here in this example we show how the bitwise OR operation work with broadcasting −
import numpy as np # Define the arrays a = np.array([1, 2, 4]) # Shape: (3,) b = np.array([[5, 6, 7]]) # Shape: (1, 3) # Perform bitwise OR with broadcasting result = np.bitwise_or(a, b) print("Array a:", a) print("Array b:", b) print("Bitwise OR result:\n", result)
Following is the Output of the above example −
Array a: [1 2 4] Array b: [[5 6 7]] Bitwise OR result: [[5 6 7]]