简体   繁体   中英

How do I replace elements in a list over a certain threshold with the previous element in that list?

I have a multiple numpy lists with thousands of data points each. There are spikes that are due to hardware issues that I wish to remove. My plan is to replace every spike with the previous element of the array to maintain consistency.

I tried to make the solution far too complicated. The easiest way is as follows;

for x in clockList:
    if x > 2000000000:
        clockList[count] = clockList[count - 1]
        count += 1
    else:
        count += 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM