NumPy - bitwise_and
L'opération ET au niveau du bit sur les bits correspondants des représentations binaires d'entiers dans les tableaux d'entrée est calculée par la fonction np.bitwise_and ().
Exemple
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)
Sa sortie est la suivante -
Binary equivalents of 13 and 17:
0b1101 0b10001
Bitwise AND of 13 and 17:
1
Vous pouvez vérifier la sortie comme suit. Considérez la table de vérité AND au niveau du bit suivant.
UNE | B | ET |
---|---|---|
1 | 1 | 1 |
1 | 0 | 0 |
0 | 1 | 0 |
0 | 0 | 0 |
1 | 1 | 0 | 1 | ||
ET | |||||
1 | 0 | 0 | 0 | 1 | |
result | 0 | 0 | 0 | 0 | 1 |