我有一个 numpy.ndarray 如下。它是 talib.RSI 的输出。它是 numpy.ndarray 的类型。我想获得 rolling(windows=3).max() 和 rolling(window=3).min 的列表
怎么做?
[ nan nan nan nan nan
nan nan nan nan nan
nan nan nan nan 56.50118203
60.05461743 56.99068148 55.70899949 59.2299361 64.19044898
60.62186599 53.96346826 44.06538636 52.04519976 51.32884016
58.65240379 60.44789401 58.94743634 59.75308787 53.56534397
54.22091468 47.22502341 51.5425848 50.0923126 49.80608264
45.69087847 50.07778871 54.21701441 58.79268406 63.59307774
66.08195696 65.49255218 65.11035657 68.47403716 70.70530564
73.21955929 76.57474822 65.89852612 66.51497688 72.42658468
73.80944844 69.56561001]
最佳答案
如果你能负担得起添加新的依赖项,我宁愿用 Pandas 来做.
import numpy
import pandas
x = numpy.array([0, 1, 2, 3, 4])
s = pandas.Series(x)
print(s.rolling(3).min())
print(s.rolling(3).max())
print(s.rolling(3).mean())
print(s.rolling(3).std())
请注意,将 NumPy 数组转换为 Pandas 系列不会创建数组的副本,因为 Pandas 在其系列内部使用 NumPy 数组。
关于python - 如何在 numpy.ndarray 上获得 rolling(window = 3).max()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44971229/