Where does the last reading go in a cyclic shift?
roll shifts an array cyclically along an axis. An element crossing an end re-enters at the other end.
numpy.roll in practice
Shift four compass readings one step and the last appears first. In forecasting, circular shifting can leak the latest reading into the earliest sample.
import numpy as np
np.roll([10,20,30,40],1)Result [40, 10, 20, 30]
中文
周期序列平移时,末尾样本去了哪里?
roll 将数组沿轴循环移动,越过某端的元素从另一端重新进入。
numpy.roll 算例
四个方位按顺时针平移一格,末尾方位出现在开头。时间预测有因果顺序,直接循环移动可能把最后一刻泄漏给最初样本。
import numpy as np
np.roll([10,20,30,40],1)结果 [40, 10, 20, 30]