找到曲线交叉点的更加pythonic的方法

时间:2016-04-25 12:41:07

标签: python sorting interpolation

我目前正在使用三次样条插值测量,如图所示:

Interpolation of a normalised harmonic signal using cubic splines.

我的想法是想找到该插值的全宽半最大值。为此,我使用了一小段代码

f = interpolate.interp1d(hhg_data, signal_array, kind='cubic')
idx2 = np.argsort(np.abs(f(hhg_interp)-0.5))

返回与行y=0.5的交集的已排序索引。但是,我想要在曲线的左边缘和右边缘的解决方案,有时它会给我两个连续的点。是否有一种优雅的pythonic方法来避免这种情况?至少比我的hacky解决方案要好得多:

idx_sorted = []
counter = 0
counter2 = 0
while(counter <= 1):
    if idx2[counter2] != idx2[counter2-1]+1 and idx2[counter2] !=   idx2[counter2-1]-1:
        idx_sorted.append(idx2[counter2])
        counter+=1
    counter2+=1

感谢您的回答!

1 个答案:

答案 0 :(得分:0)

假设var responses = []; $http({ ... }).then(function (response) { responses.push(response); return $http({ ... }); }).then(function (response) { responses.push(response); console.log(responses[0], responses[1]); }); 已排序且只有一个最大值且想要进行网格搜索(即在离散点计算函数并使用这些值),我会执行以下操作:

hhg_interp

这是您要查找的信息吗?