本文整理汇总了Python中BitVector.count_bits_sparse方法的典型用法代码示例。如果您正苦于以下问题:Python BitVector.count_bits_sparse方法的具体用法?Python BitVector.count_bits_sparse怎么用?Python BitVector.count_bits_sparse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitVector
的用法示例。
在下文中一共展示了BitVector.count_bits_sparse方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: print
# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import count_bits_sparse [as 别名]
print(bv.count_bits()) # 0
print("\nTest set_value idea:")
bv = BitVector(intVal=7, size=16)
print(bv) # 0000000000000111
bv.set_value(intVal=45)
print(bv) # 101101
print("\nTesting count_bits_sparse():")
bv = BitVector(size=2000000)
bv[345234] = 1
bv[233] = 1
bv[243] = 1
bv[18] = 1
bv[785] = 1
print("The number of bits set: " + str(bv.count_bits_sparse())) # 5
print("\nTesting Jaccard similarity and distance and Hamming distance:")
bv1 = BitVector(bitstring='11111111')
bv2 = BitVector(bitstring='00101011')
print("Jaccard similarity: " + str(bv1.jaccard_similarity(bv2))) # 0.5
print("Jaccard distance: " + str(bv1.jaccard_distance(bv2))) # 0.5
print("Hamming distance: " + str(bv1.hamming_distance(bv2))) # 4
print("\nTesting next_set_bit():")
bv = BitVector(bitstring='00000000000001')
print(bv.next_set_bit(5)) # 13
bv = BitVector(bitstring='000000000000001')
print(bv.next_set_bit(5)) # 14
bv = BitVector(bitstring='0000000000000001')
print(bv.next_set_bit(5)) # 15