Use py to count the number of binary 1
Implemented for example as follows :( tanimoto similarity function)
def getOneNum(bits):
countOne = 0
while bits:
countOne = countOne+1
bits = bits&(bits-1)
return float(countOne)
def tanimoto(X, Y):
XYbits = X&Y
return getOneNum(XYbits)/(getOneNum(X)+getOneNum(Y)-getOneNum(XYbits))
print(tanimoto(0b011010,0b100111))
Further information about using non-binary data to calculate the similarity matrix tanimoto the like, may refer to:
https://e3fp.readthedocs.io/en/latest/_modules/e3fp/fingerprint/metrics.html#tanimoto
https://github.com/keiserlab/e3fp/blob/1.1/e3fp/fingerprint/metrics/array_metrics.py