📜  滚动窗口二维数组 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:47.801000             🧑  作者: Mango

代码示例1
# Rolling window for 2D arrays in NumPy
import numpy as np

def rolling_window(a, shape):  # rolling window for 2D array
    s = (a.shape[0] - shape[0] + 1,) + (a.shape[1] - shape[1] + 1,) + shape
    strides = a.strides + a.strides
    return np.lib.stride_tricks.as_strided(a, shape=s, strides=strides)