In this chapter, we will discuss about NumPy bitwise and. The bitwise AND operation on the corresponding bits of binary representations of integers in input arrays are computed by np.bitwise_and() function.
Example Of NumPy bitwise and
import numpy as np 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 np.bitwise_and(13, 17)
Its output is as follows −
Binary equivalents of 13 and 17: 0b1101 0b10001 Bitwise AND of 13 and 17: 1
You can verify the output as follows. Consider the following bitwise AND truth table.
A | B | AND |
---|---|---|
1 | 1 | 1 |
1 | 0 | 0 |
0 | 1 | 0 |
0 | 0 | 0 |
1 | 1 | 0 | 1 | ||
AND | |||||
1 | 0 | 0 | 0 | 1 | |
result | 0 | 0 | 0 | 0 | 1 |
Next Topic- Click Here
Pingback: NumPy - Binary Operators - Adglob Infosystem Pvt Ltd
Pingback: NumPy bitwise or - Adglob Infosystem Pvt Ltd .........
Pingback: NumPy - Copies & Views - Adglob Infosystem Pvt Ltd
Pingback: NumPy - Matrix Library - Adglob Infosystem Pvt Ltd