我正在尝试查找异常值的索引号。基于与中位数的差异,我能够得到正确的高数,但只要低数是异常值,我就只能得到高数..
import numpy as np
def findoutlier(lis):
outliermax = np.absolute(np.max(lis) - np.median(lis))
outliermin = np.absolute(np.min(lis) - np.median(lis))
if outliermax > outliermin:
argmax = np.argmax(lis, axis = 1)
return argmax
else:
argmin = np.argmin(lis, axis = 1)
return argmin
def main():
Matx = np.array([[10,3,2],[1,2,6]])
print(findoutlier(Matx))
threeMatx = np.array([[1,10,2,8,5],[2,7,3,9,11],[19,2,1,1,5]])
print(findoutlier(threeMatx))
main()