如何确定一系列循环数据中的高低值? [英] How do I determine the high and low values in a series of cyclic data?

查看:32
本文介绍了如何确定一系列循环数据中的高低值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代表周期性运动的数据.所以,它从高到低,然后又回来;如果你要绘制它,它会像一个正弦波.然而,振幅在每个周期中略有不同.我想列出整个序列中的每个最大值和最小值.如果有 10 个完整的周期,我最终会得到 20 个数字,10 个正数(高)和 10 个负数(低).

I've got some data that represents periodic motion. So, it goes from a high to a low and back again; if you were to plot it, it would like a sine wave. However, the amplitude varies slightly in each cycle. I would like to make a list of each maximum and minimum in the entire sequence. If there were 10 complete cycles, I would end up with 20 numbers, 10 positive (high) and 10 negative (low).

这似乎是一份时间序列分析的工作,但我对统计数据不够熟悉,无法确定.

It seems like this is a job for time series analysis, but I'm not familiar with statistics enough to know for sure.

我在 python 中工作.

I'm working in python.

谁能给我一些关于代码库和术语方面的指导?

Can anybody give me some guidance as far as possible code libraries and terminology?

推荐答案

如果您不想使用库,这不是一个过于复杂的问题,像这样的事情应该可以满足您的需求.基本上,当您遍历数据时,如果从上升到下降,您会得到一个高点,而从下降到上升,您会得到一个低点.

This isn't an overly complicated problem if you didn't want to use a library, something like this should do what you want. Basically as you iterate through the data if you go from ascending to descending you have a high, and from descending to ascending you have a low.

def get_highs_and_lows(data):
    prev = data[0]
    high = []
    low = []
    asc = None
    for value in data[1:]:
        if not asc and value > prev:
            asc = True
            low.append(prev)
        elif (asc is None or asc) and value < prev:
            asc = False
            high.append(prev)
        prev = value
    if asc:
        high.append(data[-1])
    else:
        low.append(data[-1])
    return (high, low)

>>> data = [0, 1, 2, 1, 0, -2, 0, 2, 4, 2, 6, 8, 4, 0, 2, 4]
>>> print str(get_highs_and_lows(data))
([2, 4, 8, 4], [0, -2, 2, 0])

这篇关于如何确定一系列循环数据中的高低值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆