I have been unable to find an example which takes a one-d array of integers as input, computes the antiderivative of the input array and returns the antiderivative array as an array of numbers representing the result of the integration.
Example: an array of accelerometer values at equal time intervals generates an output array of velocity values at the same equal time intervals.
You mean, like, a cumulative sum?
Searching with that term immediately shows a Numpy builtin for code that’s already using Numpy, as well as a high quality Stack Overflow Q&A:
Not sure. The explanations contain so many alternatives I’m left uncertain what the function does.
Let’s say I do this in C++. I would calculate the area of each trapezoid and place the sum into the corresponding array element on the velocity array. So if the input array is a trivial set of 1’s (constant acceleration), the output array would be 1,2,3,4, for the velocities, corresponding to the equation velocity = acceleration (1) x time.
Is this what the numby function would put into the output array?
Please try it, read the documentation, and assess for yourself.
from scipy import integrate
import matplotlib.pyplot as plt
import scipy as np
x = np.linspace(-2, 2, num=20)
y = x
y_int = integrate.cumtrapz(y, x, initial=0)
plt.plot(x, y_int, ‘ro’, x, y[0] + 0.5 * x**2, ‘b-’)
plt.show()
This works entered via IDLE Shell