Your basic function 'running_avg' seeems to be working perfectly. However, If you want answers exactly as you would get using movmean then you should understand how movmean works.
movmean does center averaging ( there are other modes for averaging too but default is center ).
Center averaging is basically to find average by keeping the current element at the center and then take previous and future elements to make the array of size specified by window. Now,
When the window is even, average is centered about the current and previous elements.
When the window is odd, average is centered about the current element.
Note : When the window needs to be shorten due to array's indexing at the endpoints, the average is taken over only the elements that can fit in the window. For e.g. if we 3 previous elements but there are only 2 previous elements then, movmean will take only 2 previous elements and shortens the window to be averaged by 1.
So, you will have to change the code for your function 'running_avg' accordingly to get output 'exactly' as movmean.
Best Answer