Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 262431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:30:54+00:00 2026-05-11T22:30:54+00:00

Given a table where the first column is seconds past a certain reference point

  • 0

Given a table where the first column is seconds past a certain reference point and the second one is an arbitrary measurement:

6   0.738158581
21  0.801697222
39  1.797224596
49  2.77920469
54  2.839757536
79  3.832232283
91  4.676794376
97  5.18244704
100 5.521878863
118 6.316630137
131 6.778507504
147 7.020395216
157 7.331607129
176 7.637492223
202 7.848079136
223 7.989456499
251 8.76853608
278 9.092367123 
    ...

As you see, the measurements are sampled at irregular time points. I need to smooth the data by averaging the reading up to 100 seconds prior each measurement (in Python). Since the data table is huge, an iterator-based method is really preferred.
Unfortunately, after two hours of coding I can’t figure out efficient and elegant solution.

Can anyone help me?

EDITs

  1. I want one smoothed reading for each raw reading, and the smoothed reading is to be the arithmetic mean of the raw reading and any others in the previous 100 (delta) seconds. (John, you are right)

  2. Huge ~ 1e6 – 10e6 lines + need to work with tight RAM

  3. The data is approximately random walk

  4. The data is sorted

RESOLUTION

I have tested solutions proposed by J Machin and yairchu. They both gave the same results, however, on my data set, J Machin’s version performs exponentially, while that of yairchu is linear. Following are execution times as measured by IPython’s %timeit (in microseconds):

data size   J Machin    yairchu
10        90.2        55.6
50          930         258
100         3080        514
500         64700       2660
1000        253000      5390
2000        952000      11500

Thank you all for the help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T22:30:54+00:00Added an answer on May 11, 2026 at 10:30 pm

    I’m using a sum result to which I’m adding the new members and subtracting the old ones. However in this way one may suffer accumulating floating point inaccuracies.

    Therefore I implement a “Deque” with a list. And whenever my Deque reallocates to a smaller size. I recalculate the sum at the same occasion.

    I’m also calculating the average up to point x including point x so there’s at least one sample point to average.

    def getAvgValues(data, avgSampleTime):
      lastTime = 0
      prevValsBuf = []
      prevValsStart = 0
      tot = 0
      for t, v in data:
        avgStart = t - avgSampleTime
        # remove too old values
        while prevValsStart < len(prevValsBuf):
          pt, pv = prevValsBuf[prevValsStart]
          if pt > avgStart:
            break
          tot -= pv
          prevValsStart += 1
        # add new item
        tot += v
        prevValsBuf.append((t, v))
        # yield result
        numItems = len(prevValsBuf) - prevValsStart
        yield (t, tot / numItems)
        # clean prevVals if it's time
        if prevValsStart * 2 > len(prevValsBuf):
          prevValsBuf = prevValsBuf[prevValsStart:]
          prevValsStart = 0
          # recalculate tot for not accumulating float precision error
          tot = sum(v for (t, v) in prevValsBuf)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 137k
  • Answers 137k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Lamport's bakery algorithm would probably work; unfortunately, there are still… May 12, 2026 at 7:24 am
  • Editorial Team
    Editorial Team added an answer CoreText can help you: CTFontGetGlyphsForCharacters (iOS 3.2 onwards) maps Unicode… May 12, 2026 at 7:24 am
  • Editorial Team
    Editorial Team added an answer This is stated in the questions linked below, but I'll… May 12, 2026 at 7:24 am

Related Questions

Consider the following table with a constraint that's a bit daft but simple enough
To adhere to 1st normal form, one of the things you must avoid is
I have a table. The table needs to store a number values about a
My database contains three tables called Object_Table , Data_Table and Link_Table . The link

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.