使用scipy执行样品的离散积分 [英] Using scipy to perform discrete integration of the sample

查看:214
本文介绍了使用scipy执行样品的离散积分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从labview移植到python.

I am trying to port from labview to python.

在Labview中,有一个函数"Integral x(t)VI",该函数将一组样本作为输入,对样本进行离散积分,并根据Simpsons规则返回值列表(曲线下的面积)

In labview there is a function "Integral x(t) VI" that takes a set of samples as input, performs a discrete integration of the samples and returns a list of values (the areas under the curve) according to Simpsons rule.

我试图在scipy中找到一个等效的功能,例如scipy.integrate.simps,但是这些函数在整个样本集中以浮点数形式返回求和积分.

I tried to find an equivalent function in scipy, e.g. scipy.integrate.simps, but those functions return the summed integral across the set of samples, as a float.

如何获取积分值列表而不是积分值之和?

How do I get the list of integrated values as opposed to the sum of the integrated values?

我只是在错误地看问题吗?

Am I just looking at the problem the wrong way around?

推荐答案

我认为您可能正在使用

I think you may be using scipy.integrate.simps slightly incorrectly. The area returned by scipy.integrate.simps is the total area under y (the first parameter passed). The second parameter is optional, and are sample values for the x-axis (the actual x values for each of the y values). ie:

>>> import numpy as np
>>> import scipy
>>> a=np.array([1,1,1,1,1])
>>> scipy.integrate.simps(a)
4.0
>>> scipy.integrate.simps(a,np.array([0,10,20,30,40]))
40.0

我想您要返回同一条曲线在不同限制之间的面积?为此,您可以传递所需的曲线部分,如下所示:

I think you want to return the areas under the same curve between different limits? To do that you pass the part of the curve you want, like this:

>>> a=np.array([0,1,1,1,1,10,10,10,10,0])
>>> scipy.integrate.simps(a)
44.916666666666671
>>> scipy.integrate.simps(a[:5])
3.6666666666666665
>>> scipy.integrate.simps(a[5:])
36.666666666666664

这篇关于使用scipy执行样品的离散积分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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