strided_window¶
- tayph.strided_window(a, L, pad=False)[source] [edit on github]¶
This function computes the rolling window over a rectangular (i.e. long in X) array as a sequence of views into the original array, eliminating the need to index. This comes from https://stackoverflow.com/questions/44305987/sliding-windows-along-last-axis-of-a-2d-array-to-give-a-3d-array-using-numpy-str
The output is what looks like a 3D array (though it doesn’t take the memory of a 3D array because it’s just a sequence of views stacked along the third axis) and you can do an operation in that direction without having to do the indexing needed to look up the values in that window from the large array.
These windows are stacked along the 0th axis.
If pad is set to False, the window only goes from the left edge to the right edge without going over. If set to True, the array is first padded with columns of NaNs such that the window effectively diminishes in size at the edges if e.g. nanmeans or nanmedians or equavalent nan-ignoring algorithms are applied later.