python - 从数组中选择中间百分比的数据
问题描述
我正在尝试从数组的中心提取点的选择。说中间的 20%(中心两边各 10% 的点)。
我可以使用数组切片选择最终和初始 x% 的数据。还有一种方法可以在数组中的某个给定点(例如中间)找到它。
no_pts = round(len(data)*percent/100)
#change here to edit number of points
sample = pts[-no_pts:]
解决方案
这就是我最终做到的方式。我不确定是否有更简洁的方法。
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]
推荐阅读
- bitbucket - BitBucket 云版本的源代码仓库是否与 Bamboo for CI/CD 一起使用?
- python - y_true 和 y_pred 有不同数量的输出 (10!=1)
- reactjs - 如何在 React JS 中的另一个函数中从一个函数中分配一个变量的值
- r - 在R中将数据帧转换为时间序列
- arduino - 将整个变量从 raspberrypi (python) 发送到 arduino 时出错
- pandas - ValueError:无法将 DataFrame 与类型的实例合并
- php - PHP如何将数组的第一个值设置为字符串变量
- python-3.x - Python 雅典娜查询
- angular5 - 如何让 cli 为我的应用程序添加 e2e 文件夹?
- swiftui - 如何使底部按钮跟随 SwiftUI 中的键盘显示