如何在Python中集成两个一维数据数组? [英] How do I integrate two 1-D data arrays in Python?

查看:307
本文介绍了如何在Python中集成两个一维数据数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个列表数据数组,x和y,但我不知道生成数据的函数.我希望能够评估数据在x轴上任何点处生成的线的积分.

I have two tabulated data arrays, x and y, and I don't know the function that generated the data. I want to be able to evaluate the integral of the line produced by the data at any point along the x-axis.

不是将分段函数插值到数据上,然后尝试将其集成到我遇到的麻烦中,有什么我可以使用的东西,可以通过评估数组来简单地提供积分?

Rather than interpolating a piecewise function to the data and then attempting to integrate that, which I am having trouble with, is there something I can use that will simply provide the integral by evaluating the arrays?

在寻找解决方案时,我看到了对iPython和Pandas的引用,但是我无法找到这些软件包中有助于该任务的部分.

When searching for solutions, I have seen references to iPython and Pandas, but I haven't been able to find the parts of those packages that will aid in this task.

如果没有一种方法可以简单地集成阵列,您能提供一些建议以最佳方式来完成此任务吗?

If there isn't a way to simply integrate the arrays, could you provide some advice on the best way to handle this task?

推荐答案

Scipy有一些不错的工具进行数值积分.

例如,您可以使用scipy.integrate.simps执行辛普森法则,并可以将其传递给以下内容:

For example, you can use scipy.integrate.simps to perform simpson's Rule, and you can pass it the following:

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

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

参数:
y:类似于数组 要集成的数组.

Parameters :
y : array_like Array to be integrated.

x:类似array_,可选 如果给出,则采样y的点.

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

dx:int,可选 积分点沿y轴的间距.仅在x为None时使用.默认值为1.

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

axis:int,可选 整合所沿的轴.默认为最后一个轴.

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

偶数:{'avg','first','str'},可选

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

"avg":平均两个结果:1)使用前N-2个间隔 最后一个区间是梯形法则,2)使用最近的N-2个区间,第一个区间是梯形法则.

‘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.

第一":对第N-2个间隔使用辛普森规则, 最后间隔上的梯形规则.

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

'last':对最后N-2个间隔使用Simpson规则, 梯形规则在第一个间隔上.

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

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

So you can use your two arrays to do numerical integration.

这篇关于如何在Python中集成两个一维数据数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆