When dealing with rolling windows, I wrote my functions in the way like list comprehension
[np.std(x[i:i+framesize]) for i in range(0, len(x)-framesize, hopsize)])]
Recently I discovered numpy.lib.stride_tricks.as_strided
and found it is used widely for rolling windows (for example, this post), even though it is a "hidden" function.
In this issue concerning why stride_tricks.as_strided is undocumented, it's mentioned that
Intentionally! It's dangerous! It was just low-level plumbing to help implement broadcast_arrays().
Is there any advantage for stride_tricks.as_strided
over the list comprehension or a for loop? I had a look at the source code of stride_tricks
but gained little.