Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从数组中选择中间百分比的数据_Python_Arrays_Database_Slice - Fatal编程技术网

Python 从数组中选择中间百分比的数据

Python 从数组中选择中间百分比的数据,python,arrays,database,slice,Python,Arrays,Database,Slice,我试图从阵列的中心提取一组点。说中间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) midd

我试图从阵列的中心提取一组点。说中间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]

坦率地说,我认为像你这样最简单的解决方案,如果令人满意,应该是第一个尝试采用的。然而,(小警告)由于舍入误差,我不能保证你得到正确的分数