Skip to content
Advertisement

Revert time averaged values to instant values with numpy

I am having a 3D field of an averaged quantity. Now I am looking for a pythonic way to revert the averaging to get instantaneous values for each time stamp. Note: The averaging is made from the beginning of the whole period. It is like rolling mean with the window size adapted to the index of the value to be averaged.

For better clarification I give an 1D example:

JavaScript

The expected result exp_result should look like this:

JavaScript

Advertisement

Answer

Something like this should work. You’re problem is very related to the reverse cumsum problem, so I’m using part of the solution given here.

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement