pythonerror-handlingunsupportedoperation

Unsupported - Tuple and Int


I've done a bit of research on this error but I still haven't been able to fix it. I've tried different syntax and codes. The error seems to be on lines mean_value= and std_value=.

# Moving Mean
for i in enumerate(inputs_filtered):
    mean_value = sum(inputs_filtered[i-smoothing:i])/smoothing

# Standard Deviation
for i in enumerate(inputs_filtered):
    std_value = math.sqrt(sum((inputs_filtered[i-smoothing:i])-mean_value)/smoothing)

Solution

  • Your problem is that using enumerate on a list is returning a tuple and not just i as you expected, it returns the index, and the value of that index.

    so in your case, i is a tuple, and you're trying to subtract smoothing off of a tuple

    e.g:

    for index, val in enumerate([10,20,30,40,50]):
        print(index, val)
    0 10
    1 20
    2 30
    3 40
    4 50
    

    If you need to iterate and fetch the value for every index, use:

    for value in inputs_filtered:
        # do something...