0

enter image description hereDoes python has an equivalent function of moving sum? I want to take the maximum value of the variable P1 and then I want to calculate the moving sum using a slide window of 9 elements.

This is my code in MATLAB:

SP = movsum(max(P1,0),[9 0]);

Thanks for any help!

Elisa m
  • 135
  • 8
  • Not in the built-in libraries. Wouldn't be surprised if `numpy` or `scipy` or the like added it, but it's not a built-in. – ShadowRanger May 03 '20 at 16:07
  • There are several ways which you can find in the dupe - you can adapt the numpy based ones by not dividing by the window size – yatu May 03 '20 at 16:08
  • @yatu can you make an example based on my code? – Elisa m May 03 '20 at 16:11
  • Well its hard to tell what the output should be, not sure what the role of [9,0] is? Can you post a minimal example and expected output? – yatu May 03 '20 at 16:11
  • @yatu yes sure. I uploaded a picture. There you can see the input variable P1. I want to identify the position of its maximum values, then i want to repeat the maximum value for 9 positions left. For the other values I want to place it 0 (instead of -2) and store the results in a new matrix called SP. This is working in Matlab but I really don't know how to write it in python – Elisa m May 03 '20 at 16:21
  • 2
    Please don't upload pictures, post a simple reduced example, and expected output. See this post on how to provide a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – yatu May 03 '20 at 16:23
  • @ShadowRanger thank you for the reply. Can you help me? – Elisa m May 03 '20 at 16:27
  • [This](https://stackoverflow.com/questions/38507672/summing-elements-in-a-sliding-window-numpy) is very close to your question. – iamvegan May 03 '20 at 16:33
  • thank you @iamvegan – Elisa m May 03 '20 at 16:35

0 Answers0