Newbie question for a kind of rolling average of list of lits - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Newbie question for a kind of rolling average of list of lits (/thread-6998.html) |
Newbie question for a kind of rolling average of list of lits - zydjohn - Dec-16-2017 Hello: I have one list of lists, like this: totals = [[1, 2, 3], [2, 3, 4], [5, 6, 7], [10, 9, 8], [4, 5, 6]]I need a function to get a kind of rolling average. The rule is: for every 2 elements in the totals list, find the average of the both elements and save them in another list of lists: In my above example, I want to get this: averages = [ [1.5, 2.5, 3.5], [3.5, 4.5, 5.5], [7.5, 8.0, 7.5], [7.0, 7.0, 7.0]]The first one: [1.5, 2.5, 3.5] is the average of [[1, 2, 3], [2, 3, 4]] The second one: [3.5, 4.5, 5.5] is the average of [[2, 3, 4], [5, 6, 7]] The third one: [7.5, 8.0, 7.5] is the average of [[5, 6, 7], [10, 9, 8]] The last one: [7.0, 7.0, 7.0] is the average of [[10, 9, 8], [4, 5, 6]] Please advise, Thanks, RE: Newbie question for a kind of rolling average of list of lits - Larz60+ - Dec-16-2017 Looks like a homework assignment, right. RE: Newbie question for a kind of rolling average of list of lits - wavic - Dec-16-2017 This sounds like a homework. Do you have any intentions to show us what you have tried so far? Put the code between code tags please - BBcode RE: Newbie question for a kind of rolling average of list of lits - ezdev - Dec-16-2017 i wish they would stop assigning lists-of-lists homework. lists of tuples, dictionaries of lists, but lists of lists? thats just setting them up. |