Python Forum
Bitwise Operations in numpy
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bitwise Operations in numpy
#1
Hi all
I am learning Numpy class they said bitwise operations but did not understand how the out put come like this

import numpy as np
a = np.array([1,2,3,4])
b = np.array([5,6,7,8])

print("a & b :",a&b)

Output

a & b : [1 2 3 0]

My doubt : What is the use of bitwise operators
How I got [1 2 3 0] this output
Reply
#2
1 & 5 = 0001 & 0101 = 0001 = 1
2 & 6 = 0010 & 0110 = 0010 = 2
3 & 7 = 0011 & 0111 = 0011 = 3
4 & 8 = 0100 & 1000 = 0000 = 0
Reply
#3
But I have a doubt how you got this 0001 & 0101 = 0001 = 1
Reply
#4
It is doing a bitwise and. Looking at the bits in the two values and creating a new value that is only the bits that are set in both. Do you understand binary numbers?
Output:
int 1 = binary b0001 int 5 = binary b0101 1 & 5 = binary b0001 = 1
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Numpy] How to store different data type in one numpy array? water 7 705 Mar-26-2024, 02:18 PM
Last Post: snippsat
  Numpy returns "TypeError: unsupported operand type(s) for *: 'numpy.ufunc' and 'int'" kalle 2 2,675 Jul-19-2022, 06:31 AM
Last Post: paul18fr
  "erlarge" a numpy-matrix to numpy-array PhysChem 2 3,030 Apr-09-2019, 04:54 PM
Last Post: PhysChem

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020