The most efficient way to calculate an integral in a dataset range
Posted
by
Annalisa
on Stack Overflow
See other posts from Stack Overflow
or by Annalisa
Published on 2011-01-11T19:50:56Z
Indexed on
2011/01/11
19:53 UTC
Read the original article
Hit count: 156
integration
|scipy
I have an array of 10 rows by 20 columns. Each columns corresponds to a data set that cannot be fitted with any sort of continuous mathematical function (it's a series of numbers derived experimentally). I would like to calculate the integral of each column between row 4 and row 8, then store the obtained result in a new array (20 rows x 1 column).
I have tried using different scipy.integrate modules (e.g. quad, trpz,...).
The problem is that, from what I understand, scipy.integrate must be applied to functions, and I am not sure how to convert each column of my initial array into a function. As an alternative, I thought of calculating the average of each column between row 4 and row 8, then multiply this number by 4 (i.e. 8-4=4, the x-interval) and then store this into my final 20x1 array. The problem is...ehm...that I don't know how to calculate the average over a given range. The question I am asking are:
- Which method is more efficient/straightforward?
- Can integrals be calculated over a data set like the one that I have described?
- How do I calculate the average over a range of rows?
© Stack Overflow or respective owner