I have a few thousand bitstrings stored as longs. Each bitstring is 1024 bits. I would like to create an array of the ratios each bit is 1.
For example (pseudocode):
bs = [
1 0 0 0,
0 1 1 0,
1 1 0 0,
0 0 0 0
]
ratios(bs) => [0.5, 0.5, 0.25 0.0]
My current slow code is:
def mean_signature(bitstrings, bit_count):
means = []
for b in range(bit_count):
m = sum((x >> b) & 1 for x in bitstrings) / len(bitstrings)
means.append(m)
return means
I am about to modify the code so the outer loop is over bitstrings, but think I must be missing something. Maybe using numpy bit arrays.
1s and0s`?dtype=object(reference).