在numpy 1d数组中查找拐点和平稳点 [英] Find Inflection and Stationary points in a numpy 1d-array

查看:220
本文介绍了在numpy 1d数组中查找拐点和平稳点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我具有以下numpy数组:

Lets assume I have the following numpy array:

import numpy as np
import matplotlib.pyplot as plt
x = np.array([11.53333333, 11.86666667, 11.1, 10.66666667, 11.2, 11.3,
              11.06666667, 12.06666667, 11.8, 13.03333333, 12.4,
              12.33333333, 12.53333333, 13.33333333, 12.43333333, 13., 13.2,
              13.76666667, 14.96666667, 19.16666667, 25.1, 32.,
              83.33333333, 103.76666667, 110.7, 118.63333333, 129.26666667,
              139.06666667, 150.3, 161.53333333, 171.16666667, 184.56666667,
              196.6, 210.26666667, 221.63333333, 231.3, 244.16666667,
              253.5, 254.66666667, 255., 255., 255., 255.,
              255., 255., 255., 255., 255., 255.,
              255., 255., 255., 255., 255., 255.,
              255., 255., 255., 255., 255.])

plt.plot(x)
plt.show()

这是绘制的输出:

如何轻松获得该图中的转折点?例如,第一个转折点在x = 20处四舍五入,另一个在 x = 37.

How can I easily get the turning points in this graph? For example the first turning point is round about at x=20, another one at x=37.

是否可以按降序获得所有转折点,所以我以后可以抓住3个最确定的转折点?

Is it possible to get all turning points in an descending order, so I can afterwards grab the 3 most destinctive turning points?

更新: 我对获取拐点

Update: I am interested in getting the Inflection Points as well as the Stationary points. Is there a simple solution in numpy / scipy?

推荐答案

有很多可能的答案-取决于您的实际需求.一种想法是通过获取移动平均数或样条曲线或其他东西来平滑数据,然后获取二阶导数并寻找其何时改变符号.这将找到近似的拐点"或转折点"-从字面上看,它将发现凹度何时发生变化.

There are many possible answers -- depending what you actually want. One idea would be to smooth the data by taking moving averages or splines or something and then take the second derivative and look for when it changes sign. This would find approximate "inflection points" or "turning points" -- literally, it would find when the concavity changes.

请参阅:

  • How to smooth a curve in the right way?
  • Derivative of an array in python?

这篇关于在numpy 1d数组中查找拐点和平稳点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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