繁体   English   中英

如何从python 2d数组中的列表中删除异常值

[英]how to remove outlier from a list in python 2d array

y2 = []

for _ in range(100):

    y2.append(round(random.uniform(1,100),1))

print(y2)
[5.3, 46.3, 7.5, 40.7, 50.3, 45.5, 15.6, 68.2, 30.4, 37.7, 43.8, 28.4, 17.8, 96.9, 49.5, 93.4, 76.2, 27.5, 21.0, 28.6, 38.7, 53.9, 36.3, 40.3, 62.3, 58.4, 92.1, 25.5, 12.9, 12.9, 14.6, 10.3, 9.4, 45.6, 84.3, 33.7, 8.1, 14.9, 37.4, 61.8, 62.9, 34.5, 23.0, 82.2, 2.4, 20.3, 65.1, 80.4, 99.5, 43.5, 48.8, 36.0, 65.7, 81.8, 72.7, 85.1, 50.8, 65.8, 4.7, 49.9, 22.3, 24.7, 80.0, 19.9, 28.0, 12.1, 90.1, 29.4, 76.8, 50.2, 76.3, 14.6, 24.2, 86.0, 92.4, 65.8, 95.5, 13.2, 26.0, 79.9, 8.9, 61.2, 62.7, 77.5, 90.2, 65.0, 77.5, 5.2, 23.4, 18.9, 86.8, 4.6, 97.4, 72.3, 54.8, 45.6, 3.5, 34.2, 1.8, 31.7]


for i in y2:

    if (y2 >= 40 and y2<=60):

        print(y2)

错误:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-172-0bd3dc8db768> in <module>
      1 for i in y2:
----> 2     if (y2 >= 40 and y2<=60):
      3         print(y2)

TypeError: '>=' not supported between instances of 'list' and 'int'

在 for 循环中,您应该将y2替换为i

import random
y2 = []

for _ in range(100):
    y2.append(round(random.uniform(1,100),1))

print(y2)

for i in y2:
    if (i >= 40 and i<=60):
        print(i)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM