sliding_window_view: from numpy.lib.stride_tricks import sliding_window_view as swv b = swv(a, n).sum(axis=1) 然而,这给出了与您的函数非常相似的结果: # generate an input with a large variability np.random.seed(0) a = 1/np.random.random(size=100_000_000)*1e-8 a.min(), a....
sliding_window_view: from numpy.lib.stride_tricks import sliding_window_view as swv b = swv(a, n).sum(axis=1) 这给出了与你的函数非常相似的结果,它似乎并不缺乏精度: # generate an input with a large variability np.random.seed(0) a = 1/np.random.random(size=100_000_000)*1e-8 ...