简体   繁体   English

计算列表中的各种实例

[英]counting various instances within a list

I've hit a wall here for a project i'm completing.我在这里遇到了一个我正在完成的项目的墙。 i've tried while loops, for loops, counts etc. i need to count instances of numbers eg.我试过 while 循环、for 循环、计数等。我需要计算数字的实例,例如。 (<=10)(>10 & <=20) etc etc (<=10)(>10 & <=20) 等等

data=[99,50,19,67,85,87,50,45,51,72,64,69,59,17,22]

while grades >=10:
    counter=0
for grades in data:
    grades[counter]=grades+1
    counter+=1

This isnt the only attempt, rather this was my last attempt before i lost my head.这不是唯一的尝试,而是我失去理智之前的最后一次尝试。

i've encountered many threads here which havent solved this.我在这里遇到了很多没有解决这个问题的线程。 it more than likely just me很可能只有我

Will appreciate any help将不胜感激任何帮助

edit - i wasnt clear, as advised by the below user.编辑 - 正如以下用户所建议的那样,我不清楚。 i require my results to look something similar to the below我要求我的结果看起来与下面类似

grades <= 10 - 2
grades >10 & <=20 - 5
grades >20 & <=30 - 7
etc
etc
etc

Using numpy :使用numpy

import numpy as np

data=np.array([99,50,19,67,85,87,50,45,51,72,64,69,59,17,22])

len(data[(data>20) & (data<=30)])
#result: 1
len(data[(data>=10)])
#result: 15

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

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