I am trying to step through a list of lists operating on each element of each list using nested for loops. I am getting a warning from PyCharm that the type of the counter in the second for loop is not certain to be an integer, despite it is derived from a range value. The code executes correctly, by why the warning?
def get_vote_fraction(cl_count, ag_vector):
v_f_vector = [[0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0, 0]]
for b in range(0, len(v_f_vector)):
for c in range(0, len(v_f_vector[b])):
v_f_vector[b][c] = f"{(ag_vector[b][c] / cl_count): .2F}"
return v_f_vector
aggregated_vector = [[0, 8, 0, 6], [0, 1, 0, 0, 0, 0, 9, 0], [0, 0, 10, 0], [0, 10, 0, 0, 0]]
class_count = 10
vote_fraction = get_vote_fraction(class_count, aggregated_vector)
print(vote_fraction)
As expected the output is [[' 0.00', ' 0.80', ' 0.00', ' 0.60'], [' 0.00', ' 0.10', ' 0.00', ' 0.00', ' 0.00', ' 0.00', ' 0.90', ' 0.00'], [' 0.00', ' 0.00', ' 1.00', ' 0.00'], [' 0.00', ' 1.00', ' 0.00', ' 0.00', ' 0.00']]
I get a warning that c in v_f_vector[b][c] can be of Unexpected type(s) (int, str) which says c is not sufficiently defined as an integer. I hesitate to raise an issue with PyCharm since I may be missing something simple. Anyone see what I am missing?