Assuming I have these two lists:
a = [1,0,0,0,1,1,1,1,1,1,1,1,0,0]
b = [0,0,0,0,1,1,1,0,0,0,1,1,0,0]
I would like to know the number of times the number 1 appears in the same position, in this case it would be 5
Assuming I have these two lists:
a = [1,0,0,0,1,1,1,1,1,1,1,1,0,0]
b = [0,0,0,0,1,1,1,0,0,0,1,1,0,0]
I would like to know the number of times the number 1 appears in the same position, in this case it would be 5
Here is what I was suggesting in my comment.
import numpy as np
a = [1,0,0,0,1,1,1,1,1,1,1,1,0,0]
b = [0,0,0,0,1,1,1,0,0,0,1,1,0,0]
result = np.logical_and(np.array(a), np.array(b))
print(np.count_nonzero(result == True))
Make the sum of the two lists then see if the result of each cell is 2 (1 + 1):
a = [1,0,0,0,1,1,1,1,1,1,1,1,0,0]
b = [0,0,0,0,1,1,1,0,0,0,1,1,0,0]
sum = [] # sun of the two lists
for x in range(len(a)):
sum.append(a[x] + b[x])
_1_in_both = []
for x in range(len(sum)):
if sum[x] == 2: # sum[x] == 2 <==> 1 in both lists
_1_in_both.append(x)
print('1 occurs in both lists', len(_1_in_both), 'times, in positions', _1_in_both)
Output:
1 occurs in both lists 5 times, in positions [4, 5, 6, 10, 11]