Hello,
I have this code script:
Here is the result of code:
Edit: I just noticed that:
My list is here:
I have this code script:
triplets = tuple(itertools.product((0, 1), repeat = 2))
freq = []
sums = {}
for row in newlist2:
print("rows",len(row))
for triple in triplets:
sums[triple] = sum(np.all((row-np.array(triple))==0, axis=1))
print("sum", sums[triple])
freq.append(sums[triple]/(len(row)))
print(sums)In this code len(row) sometimes is correct but sometimes is not correct(it comes as len(row)-1 or len(row)+1)Here is the result of code:
newlist2 [[[0, 0], [1, 1], [1, 1], [0, 0], [1, 1], [0, 0], [0, 0], (0.7853981633974483, 0.7853981633974483)], [[0, 0], [0, 0], [0, 0], (0, 0)], [[0, 0], [1, 1], [0, 0], [0, 0], [1, 1], [0, 0], [0, 0], (0.7853981633974483, 0)], [[0, 0], [0, 0], [1, 1], (0, 0.7853981633974483)]]
rows 8
sum 4
sum 0
sum 0
sum 3
{(0, 0): 4, (0, 1): 0, (1, 0): 0, (1, 1): 3} #For instance here 4+3 = 7 but it comes as 8
rows 4
sum 4
sum 0
sum 0
sum 0
{(0, 0): 4, (0, 1): 0, (1, 0): 0, (1, 1): 0} #Here is ok
rows 8
sum 5
sum 0
sum 0
sum 2
{(0, 0): 5, (0, 1): 0, (1, 0): 0, (1, 1): 2} #Here is 5+2=7 but it comes as 8
rows 4
sum 2
sum 0
sum 0
sum 1
{(0, 0): 2, (0, 1): 0, (1, 0): 0, (1, 1): 1} #Here 2+1=3 but it comes as 4
freq: [0.5, 0.0, 0.0, 0.375, 1.0, 0.0, 0.0, 0.0, 0.625, 0.0, 0.0, 0.25, 0.5, 0.0, 0.0, 0.25]I did not understand why it is happening. Can you please help me?Edit: I just noticed that:
My list is here:
newlist2 [[[0, 0], [1, 1], [1, 1], [0, 0], [1, 1], [0, 0], [0, 0], (0.7853981633974483, 0.7853981633974483)], [[0, 0], [0, 0], [0, 0], (0, 0)], [[0, 0], [1, 1], [0, 0], [0, 0], [1, 1], [0, 0], [0, 0], (0.7853981633974483, 0)], [[0, 0], [0, 0], [1, 1], (0, 0.7853981633974483)]]When I am in the for loop in newlist2 I am also counting last element of sublist and if last element of sublist includes "(0,0)" then the number of (0,0) increases. How can I prevent it? I should not count last element of sublist of newlist2. I actually should not count inside "()", I should just count "[]"
