gpt4 book ai didi

python - 如何减少列表中特定点周围的点?

转载 作者:行者123 更新时间:2023-12-01 00:54:19 26 4
gpt4 key购买 nike

我不知道如何解释这个概念,如果我这样做的话,我可能已经在 Google 上找到了答案。

我想要做的是获取 y 点列表并减少特定选定点上方和下方的所有值。可能位于图表的中间,可能位于开头,等等。

有了图片就更容易了。这是我想要做的事情的可视化。

enter image description here

你可以看到我选择“减少”它周围的点的点。

我编写了这个过于复杂的函数来做到这一点:

import numpy as np
x = [0.0, 4.8, 9.0, 11.3, 13.6, 17.1, 23.1, 29.5, 35.1, 39.8, 42.2]
y = [1.35, 1.36, 1.39, 1.43, 1.46, 1.48, 1.49, 1.53, 1.59, 1.68, 1.8]

squash_around = 1.43
squash_min = min([i-squash_around for i in y])
squash_max = max([i-squash_around for i in y])
y = [np.interp(i-squash_around, [squash_min, 0, squash_max], [.9, 1.0, 1.1])*i for i in y]

enter image description here

但是,它无法正确处理某些数据,例如我将 squash_around 设置为 .2,因此它应该修改除左上角之外的所有点,但事实并非如此:

enter image description here

如果有人可以向我指出可能重复的问题,那就太好了。

最佳答案

看来您想要“减少”的是兴趣点(即圈出的点)与每个其他点的 y 值之间的 y 值差异。

如果我们让 (x, y)是你想要“减少”的点周围,那么我们可以“减少”另一个点(x1, y1)相对于(x, y)系数 a进行以下转换

(x1, y1) => (x1, y + (y1 - y) * a)

如果0 < a < 1然后(x, y)准确地保持在原来的位置,点位于y下方向上移动,上面的点 y向下朝它移动。将其放入 numpy 代码

import numpy as np
x = np.array([0.0, 4.8, 9.0, 11.3, 13.6, 17.1, 23.1, 29.5, 35.1, 39.8, 42.2])
y = np.array([1.35, 1.36, 1.39, 1.43, 1.46, 1.48, 1.49, 1.53, 1.59, 1.68, 1.8])

i = 5 # the index of the point to "reduce" around
a = 0.5 # reduction factor

reduced = y[i] + (y - y[i]) * a

# plt.plot(x, y)
# plt.plot(x, reduced)

enter image description here

这是您正在寻找的那种减少吗?

关于python - 如何减少列表中特定点周围的点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56334233/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com