问题描述:

I have a time series `x(t)`

that is a NumPy array. My assignment tells me that I need to find the integral of this data with time.

How am I supposed to do this? It's not a function that I need to integrate, it's a list of data.

It depends on the statement of the problem. A rude approach would be something like this

```
import numpy as np
import scipy as sp
t = np.linspace(-1, 1, 100)
x = t*t
delta = t[1] - t[0]
I = sum(delta*x)
```

You can use *Simpson's Rule*. A routine that does that for you is `simps`

in `spicy.integrate`

.

```
>>> help(scipy.integrate.simps)
Help on function simps in module scipy.integrate.quadrature:
simps(y, x=None, dx=1, axis=-1, even='avg')
Integrate y(x) using samples along the given axis and the composite
Simpson's rule. If x is None, spacing of dx is assumed.
If there are an even number of samples, N, then there are an odd
number of intervals (N-1), but Simpson's rule requires an even number
of intervals. The parameter 'even' controls how this is handled.
```

您可能感兴趣的文章：

- node.js - invalid_client on initial setup of node-restify-oauth2-mongodb
- pbs - How can I see the `qsub` command used to submit a job?
- coldfusion - Date Field Mask Not Working
- javascript - How to get all unique elements in for an array of array but keep max count of duplicates
- validation - 4 Digit Pin Regex
- php - Reading a specific line from a text file
- clr - Any implementation of an Unrolled Linked List in C#?
- Finding Hudson Log Files
- Forward to a payment-gateway together with POST data using cURL (or any other PHP server side solution)
- WCF in Winforms app - is it always single-threaded?

随机阅读：

**推荐内容**-

**热点内容**-
- php - Reading a specific line from a text file
- clr - Any implementation of an Unrolled Linked List in C#?
- Finding Hudson Log Files
- WCF in Winforms app - is it always single-threaded?
- git svn - git svn fetch does not fetch a Subversion commit message modified after initial clone
- java me - Why I am getting the bad length exception when I am running this application?
- java - How to get string.format to complain at compile time
- ruby on rails - Trigger observer of parent class on change
- python - Issue with URL pattern in Django with webmonkey tutorial