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 7667929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:13:41+00:00 2026-05-31T15:13:41+00:00

I have a dataset and am trying to work out where there are peaks

  • 0

I have a dataset and am trying to work out where there are peaks in the data; a data point with a higher value than the point before and after it.

I have code which works for one dataset but now transferring it to another dataset brings up index out of range error for certain lines.

The code I have is:

for line in file.readlines():
    peaks.append(0)
    line = line.split(',')
    time.append(float(line[0]))
    TP.append(float(line[3]))
    level.append(float(line[5]))


for i in range(len(level)-1):
    i = i + 1
    if (level[i] > level[i-1]) and (level[i] > level[i+1]):
        peaks[i] = 1
        noPeaks = noPeaks +1

print noPeaks

Yet for one line (so far) it says data is out of range – visually inspecting the data doesn’t suggest this – the value is higher than the previous value but lower than the next so on a rising limb of the graph.

Any help would be great!

  • 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-31T15:13:42+00:00Added an answer on May 31, 2026 at 3:13 pm

    I cannot see your loop but the (level[i] > level[i+1]) suggests that you are forgetting to put

    for i in range(1,len(list)-1)
    

    key to note there is that -1 since you’re doing that +1 and the range only goes to max-1 anyway.

    Starting your loop at 0 would not throw an out of bounds error since list[-1] is perfectly legal in python. however, i dont think you want your first comparison to be list[-1] > list[0]


    Due to edit,
    You do not need to do the

    i = i + 1

    line in you’re code, you will hit the length of the list because the for loop will also increment, causing an out of bounds error. Remove that line and it should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dataset that i am trying to set the default value as
I have the following data set that I am trying to plot with ggplot2,
I have a very large possible data set that I am trying to visualize
I´m trying to set a cell of type System.Int32 in a DataSet by code,
I'm trying to write some code to convert data from a object type field
i am trying to figure out how to input data values into highcharts. Firstly
I'm trying to visualize some data I have stored on a regular grid using
I've spent a long time trying to work this out, but no success thus
I'm trying to figure out the best way to normalize the following data set,
Alright I have been trying to figure this out and I read the MSDN

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.