
- 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_and() Function
The NumPy bitwise_and() function performs a bitwise AND operation on corresponding elements of two arrays. This function compares the binary representations of the input elements by setting each bit in the result to 1 if both corresponding bits in the input arrays are 1 otherwise, the bit is set to 0.
This operation is element-wise which means processes each pair of elements from the input arrays independently. The bitwise_and() supports broadcasting, allowing it to handle arrays of different shapes by aligning them according to broadcasting rules.
This function is useful for binary data manipulation and low-level data processing. Below are the results of bitwise AND operation of bit combinations 1 and 0 −
- Bitwise AND of 0 and 0: 0
- Bitwise AND of 0 and 1: 0
- Bitwise AND of 1 and 0: 0
- Bitwise AND of 1 and 1: 1
Syntax
Following is the syntax of Numpy bitwise_and() function −
numpy.bitwise_or(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
Parameters
Following are the Parameters of Numpy bitwise_and() function −
- x1: First input array or scalar.
- x2: Second input array or scalar. Must be broadcastable to the shape of x1.
- out(Optional): A location into which the result is stored. If provided then it must have a shape that matches the broadcasted output of x1 and x2.
- where(Optional): A condition to determine where the operation is performed. The result is computed where this condition is True.
- **kwargs: Additional keyword arguments.
Return value
This function returns the array with the result of bitwise AND operation.
Example 1
Following is the basic example of Numpy bitwise_and() function. Here this example shows how to compute the bitwise AND of two numbers −
import numpy as np # Print binary equivalents of 13 and 17 print('Binary equivalents of 13 and 17:') a, b = 13, 17 print(bin(a), bin(b)) print('\n') # Print bitwise AND of 13 and 17 print('Bitwise AND of 13 and 17:') print(np.bitwise_and(a, b))
Below is the output of bitwise_and() function applied on numbers 13 and 17 −
Binary equivalents of 13 and 17: 0b1101 0b10001 Bitwise AND of 13 and 17: 1
Example 2
Here in this example we show how to create two 2D NumPy arrays by displaying their properties and computing their element-wise bitwise AND−
import numpy as np # Creating two numpy arrays using the array() method # We have inserted elements of int type arr1 = np.array([[49, 6, 61], [82, 69, 29]]) arr2 = np.array([[40, 60, 61], [81, 55, 32]]) # Display the arrays print("Array 1:", arr1) print("Array 2:", arr2) # Get the type of the arrays print("Our Array 1 type:", arr1.dtype) print("Our Array 2 type:", arr2.dtype) # Get the dimensions of the Arrays print("Our Array 1 Dimensions:",arr1.ndim) print("Our Array 2 Dimensions:",arr2.ndim) # Get the shape of the Arrays print("Our Array 1 Shape:",arr1.shape) print("Our Array 2 Shape:",arr2.shape) # To compute the bit-wise AND of two arrays element-wise, use the numpy.bitwise_and() method in Python Numpy print("Result:",np.bitwise_and(arr1, arr2))
Following is the output for the above example −
Array 1: [[49 6 61] [82 69 29]] Array 2: [[40 60 61] [81 55 32]] Our Array 1 type: int64 Our Array 2 type: int64 Our Array 1 Dimensions: 2 Our Array 2 Dimensions: 2 Our Array 1 Shape: (2, 3) Our Array 2 Shape: (2, 3) Result: [[32 4 61] [80 5 0]]