python - 如何在 Python 中集成两个一维数据数组?

标签 python arrays integration interpolation

我有两个表格数据数组,x 和 y,但我不知道生成数据的函数。我希望能够计算数据在 x 轴上任意点生成的直线的积分。

与其对数据插值一个分段函数,然后尝试对其进行积分,这让我遇到了麻烦,有什么我可以使用的东西可以通过评估数组来简单地提供积分吗?

在搜索解决方案时,我看到了对 iPython 和 Pandas 的引用,但我无法找到这些包中有助于完成此任务的部分。

如果没有简单集成阵列的方法,您能否就处理此任务的最佳方法提供一些建议?

最佳答案

Scipy has some nice tools to perform numerical integration.

例如,您可以使用 scipy.integrate.simpson执行辛普森法则,您可以通过以下方式传递给它:

scipy.integrate.simps(y, x=None, dx=1, axis=-1, even='avg')

Parameters :
y : array_like Array to be integrated.

x : array_like, optional If given, the points at which y is sampled.

dx : int, optional Spacing of integration points along axis of y. Only used when x is None. Default is 1.

axis : int, optional Axis along which to integrate. Default is the last axis.

even : {‘avg’, ‘first’, ‘str’}, optional

‘avg’ : Average two results:1) use the first N-2 intervals with a trapezoidal rule on the last interval and 2) use the last N-2 intervals with a trapezoidal rule on the first interval.

‘first’ : Use Simpson’s rule for the first N-2 intervals with a trapezoidal rule on the last interval.

‘last’ : Use Simpson’s rule for the last N-2 intervals with a trapezoidal rule on the first interval.

因此您可以使用您的两个数组进行数值积分。

关于python - 如何在 Python 中集成两个一维数据数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17602076/

相关文章:

php - 试图获得非对象的属性? PHP/代码点火器

c - 在 C 语言中声明数组类型是否是错误的编程习惯?

C - 蒙特卡洛积分 - 随机不是随机且计数不计数?

java - 当我们有Rest API来调用不同的应用程序时,为什么还要使用jitterbit或informatica等集成工具?

python - SQLAlchemy 提交对通过 __dict__ 修改的对象的更改

python - 安装 colorama 时遇到问题

ios - 如何检查 UITextField 的输入是否与数组中的 Core Data 属性匹配?

gitlab - 将 Nexus Repo 复制到 GitLab 注册表

python - 如何构建5x5矩阵?

python - Python 中 {str} 和 {str_} 的区别