【问题标题】:How to find an element in an array that corresponds to the second array in python?如何在数组中找到对应于python中第二个数组的元素?
【发布时间】:2021-09-08 17:52:32
【问题描述】:

我有两个一维数组:

x  y
0  5
2  10
4  15
6  20
8  25
10 30

我想在给定的x 处找到y 的值。但是元素不在数组中,而是元素的值在这些元素之间。例如,我想在x = 2.5x = 5 时找到y 的值。我可能应该使用 interpolate 函数,但我发现它非常混乱。

【问题讨论】:

  • 什么,确切地你有吗?你在处理列表吗?还是 Numpy 数组?这就是你所说的“插值函数”吗?请始终提供minimal reproducible example

标签: python arrays python-3.x interpolation


【解决方案1】:

要在值之间进行插值,我建议使用scipy.interpolate.interp1d

from scipy.interpolate import interp1d
f = interp1d(x, y)

这将创建一个函数f,您可以将值传入其中,它将返回插值。即f(3) 将输出12.5

【讨论】:

  • 谢谢您,先生。 @汤姆麦克莱恩
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-11-23
  • 2017-06-18
  • 1970-01-01
  • 2015-01-08
  • 2017-06-01
  • 2021-10-27
  • 1970-01-01
相关资源
最近更新 更多