Python Forum
Newbie question for a kind of rolling average of list of lits
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Newbie question for a kind of rolling average of list of lits
#1
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,
Reply
#2
Looks like a homework assignment, right.
Reply
#3
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
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#4
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How is pandas modifying all rows in an assignment - python-newbie question markm74 1 729 Nov-28-2023, 10:36 PM
Last Post: deanhystad
  newbie question - can't make code work tronic72 2 717 Oct-22-2023, 09:08 PM
Last Post: tronic72
  Newbie question about switching between files - Python/Pycharm Busby222 3 644 Oct-15-2023, 03:16 PM
Last Post: deanhystad
  Newbie.... run for cover. OpenCV question Stevolution2023 2 1,000 Apr-12-2023, 12:57 PM
Last Post: Stevolution2023
  numpy newbie question bcwilly_ca 4 1,223 Feb-10-2023, 05:55 PM
Last Post: jefsummers
  What kind of list is this? jesse68 2 1,167 Jun-29-2022, 05:02 PM
Last Post: rob101
  How to efficiently average same entries of lists in a list xquad 5 2,176 Dec-17-2021, 04:44 PM
Last Post: xquad
  Question from complete python's newbie Davicom 3 2,408 Jun-09-2021, 06:09 PM
Last Post: bowlofred
  splitting lines, need to add element of same kind tester_V 6 3,196 Feb-20-2021, 11:51 PM
Last Post: tester_V
  Newbie question about running Python via GUI on OSX ejwjohn 8 3,607 Feb-05-2021, 03:20 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020