【发布时间】:2017-05-23 22:18:36
【问题描述】:
我有来自传感器数据的文本文件,例如加速度计和陀螺仪,例如:
% Accelerometer data recorded with 'snsrlog'
%
% Sampling frequency: 100 Hz
%
% Label description:
% 0: Default Label
% 1: pick up phone
%
% Column description:
% 1: Seconds.milliseconds since 1970
% 2: Number of skipped measurements
% 3: Acceleration value in x-direction
% 4: Acceleration value in y-direction
% 5: Acceleration value in z-direction
% 6: Label used for the current sample
%
%
1495573445.162 0 0.021973 0.012283 -0.995468 1
1495573445.172 0 0.021072 0.013779 -0.994308 1
1495573445.182 0 0.020157 0.015717 -0.995575 1
1495573445.192 0 0.017883 0.012756 -0.993927 1
1495573445.202 0 0.021194 0.012161 -0.994705 1
1495573445.212 0 0.019638 0.013718 -0.994019 1
1495573445.222 0 0.019440 0.010803 -0.994476 1
文件中有更多内容。
我想为加速度计轴的每一列创建一个大小为 50 的滑动窗口,因为采样频率为 100Hz。我可以像这样打印出第一列的每一行:
def sliding_window(filename, stepSize, windowSize):
with open(filename) as infile:
for line in infile:
print(line.split()[0])
但是,我不应该打印前 17 行,因为它们只是文本文件中的 cmets。我将如何制作这个滑动窗口?
【问题讨论】:
-
糟糕。我不应该那样做的。我会编辑它。
标签: python text sliding-window