Find Inflection and Stationary points in a numpy 1d-array

前端 未结 2 1825
我寻月下人不归
我寻月下人不归 2021-01-14 18:14

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, 1         


        
2条回答
  •  不要未来只要你来
    2021-01-14 18:45

    I was looking for this answer too. This is one way how to find inflection point in python:

    How to find the inflection point in a noisy curve?

    The inflection point is [x0, y0]

    #!/usr/bin/env python2.7
    # -*- coding: utf-8 -*-
    import matplotlib.pyplot as plt
    import numpy as np
    from scipy.ndimage import gaussian_filter
    
    
    def generate_fake_data():
        """Generate data that looks like an example given."""
        xs = np.arange(0, 25, 0.05)
        ys = - 20 * 1./(1 + np.exp(-(xs - 5.)/0.3))
        m = xs > 7.
        ys[m] = -20.*np.exp(-(xs - 7.)[m] / 5.)
    
        # add noise
        ys += np.random.normal(0, 0.2, xs.size)
        return xs, ys
    
    
    def main():
        xs, ys = generate_fake_data()
    
        # smooth out noise
        smoothed = gaussian_filter(ys, 3.)
    
        # find the point where the signal goes above the background noise
        # level (assumed to be zero here).
        base = 0.
        std = (ys[xs < 3] - base).std()
        m = smoothed < (base - 3. * std)
        x0 = xs[m][0]
        y0 = ys[m][0]
    
        plt.plot(xs, ys, '.')
        plt.plot(xs, smoothed, '-')
        plt.plot(x0, y0, 'o')
        plt.show()
    
    
    if __name__ == '__main__':
        main()
    

    Example output of how to find inflection point in python

提交回复
热议问题