np.diff has keyword for `n-th order discrete difference`
but cumsum has different arguments and cannot integrate n times
What's the best "inverse function" for np.diff with n>1?
I briefly tried polynomial, but without success so far.
need two starting values to integrate for n=2
>>> a = np.random.randn(10)
>>> a - np.cumsum(np.r_[a[0], np.cumsum(np.r_[a[1]-a[0], np.diff(a, n=2)])])
array([ 0.00000000e+00, 0.00000000e+00, 1.11022302e-16,
2.22044605e-16, 3.33066907e-16, 2.22044605e-16,
1.11022302e-16, 2.77555756e-16, 5.55111512e-16,
8.88178420e-16])
>>> a - np.concatenate((a[:2], np.cumsum(np.cumsum(np.diff(a, n=2))) + a[0] +
>>> np.arange(2, len(a)) * (a[1] - a[0])))
array([ 0.00000000e+00, 0.00000000e+00, 1.11022302e-16,
2.22044605e-16, 3.33066907e-16, 2.22044605e-16,
1.11022302e-16, 2.77555756e-16, 5.55111512e-16,
1.77635684e-15])
Josef
_______________________________________________
NumPy-Discussion mailing list
[email protected]
http://mail.scipy.org/mailman/listinfo/numpy-discussion