0

I know this may be a fairly simple question, but I am struggling to figure it out for hours.

I am trying to use a for loop to access to each of the values in the tuple to calculate the probability per tuple.

for i in range(len(grouped)):
    probabilities[class_number] *= summarise_list[i]

The summarise_list[i]:

[(3031.660194174757, 136.76461483348012, 103), (136.64077669902912, 113.70531696131526, 103), (11.03883495145631, 5.842579221772521, 103), (324.9611650485437, 233.42685474528514, 103), (36.12621359223301, 40.204057841157116, 103), (4325.728155339806, 1102.084194803101, 103), (216.28155339805826, 18.280718158399203, 103), (223.4368932038835, 17.165669057009026, 103), (140.54368932038835, 25.034398569681457, 103), (4300.592233009709, 1621.3665105421753, 103)]
[(3031.660194174757, 136.76461483348012, 103), (136.64077669902912, 113.70531696131526, 103), (11.03883495145631, 5.842579221772521, 103), (324.9611650485437, 233.42685474528514, 103), (36.12621359223301, 40.204057841157116, 103), (4325.728155339806, 1102.084194803101, 103), (216.28155339805826, 18.280718158399203, 103), (223.4368932038835, 17.165669057009026, 103), (140.54368932038835, 25.034398569681457, 103), (4300.592233009709, 1621.3665105421753, 103)]
...
...

The idea is to iterate through the tuple, look into i (x,x,x), compare only the first two values within (x,x,x) and return the highest value to be calculated in probabilities[class_number] multiplication.

For example, (3031.660194174757, 136.76461483348012, 103) will return 3031.660194174757. Next i, (136.64077669902912, 113.70531696131526, 103) will return 136.64077669902912. 103 (the third element) will be ignored in all cases. The result of 3031, 136 and so on will be multiplied. This will need to be done in every tuple to find every probability per tuple.

Efficiency is important here as I will have to process thousands of rows.

Appreciate any help, thank you.

Side note: I have read through Accessing a value in a tuple that is in a list but still could not resolve it.

1 Answers1

0

You can do this by slicing the tuple and using the max function:

for i in range(len(grouped)):
    probabilities[class_number] *= max(summarise_list[i][:2])
Ryan Laursen
  • 617
  • 4
  • 18