【发布时间】:2014-04-22 05:48:59
【问题描述】:
我有一个元组列表,即具有 x 和 y 值的 2-dim 元组。称之为数据。我想取两个浮点数,xmin 和 xmax,并返回该间隔上最大 y 值的索引。 即使 xmin 和 xmax 与数据点不完全匹配,它也应该可以工作。
除了将 xmin 和 xmax 舍入到列表中最接近的值之外,我了解如何解决此问题。我不知道,因为我是 python 新手。
# Find the index of the point (x, y) with the maximum y value
# on the interval [xmin, xmax]
def find_peak(data, xmin, xmax):
暂时,我可以搜索列表并记录每个 x 值的最小差异。这可行还是有更聪明的方法?
【问题讨论】: