首页 > 解决方案 > 从数组中选择中间百分比的数据

问题描述

我正在尝试从数组的中心提取点的选择。说中间的 20%(中心两边各 10% 的点)。

我可以使用数组切片选择最终和初始 x% 的数据。还有一种方法可以在数组中的某个给定点(例如中间)找到它。

no_pts = round(len(data)*percent/100)

#change here to edit number of points
sample = pts[-no_pts:]

标签: pythonarraysdatabaseslice

解决方案


这就是我最终做到的方式。我不确定是否有更简洁的方法。

no_pts = round(len(data)*percent/100)

middle_point = round(len(data)/2)

sample = pts[middle_point-no_points/2 : middle_point + no_pts/2]

推荐阅读