>>> import numpy as np
>>> a=np.array([2,3,5,2,34,1])
>>> np.percentile(a,80)
5.0
>>> np.where(a<5)
(array([0, 1, 3, 5], dtype=int64),)
>>> np.where(a<np.percentile(a,80))
(array([0, 1, 3, 5], dtype=int64),)
>>> b=np.where(a<np.percentile(a,80))
>>> b
(array([0, 1, 3, 5], dtype=int64),)
np.where 是条件表达式
np.percentile是取数组的百分数
百分位数是统计中使用的度量,表示小于这个值的观察值占总数q的百分比。 函数numpy.percentile()
接受以下参数。
numpy.percentile(a, q, axis)
内容借鉴: