Post Reply 
Ranks calculation
10-31-2024, 04:41 PM
Post: #5
RE: Ranks calculation
Code:
def ranking(m):
    hi = len(m)
    m2 = zip(m, range(hi))
    m2.sort()        # sort with index
    lo, m3 = 0, m[:] # work with a copy
    for i in range(hi):
        j = i+1
        if j != hi and m2[i][0]==m2[j][0]: continue    
        r = (lo+i)/2 # j-lo items have same ranking
        for k in range(lo,j): m3[m2[k][1]] = r+1
        lo = j
    return m3

p2> ranking([1,3,5,1,4,5,6,1])
[2.0, 4.0, 6.5, 2.0, 5.0, 6.5, 8.0, 2.0]
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Ranks calculation - robmio - 10-31-2024, 01:39 PM
RE: Ranks calculation - Albert Chan - 10-31-2024, 02:38 PM
RE: Ranks calculation - robmio - 10-31-2024, 02:46 PM
RE: Ranks calculation - robmio - 10-31-2024, 02:50 PM
RE: Ranks calculation - Albert Chan - 10-31-2024 04:41 PM
RE: Ranks calculation - robmio - 10-31-2024, 08:16 PM
RE: Ranks calculation - Albert Chan - 10-31-2024, 08:42 PM
RE: Ranks calculation - robmio - 11-01-2024, 07:41 AM
RE: Ranks calculation - robmio - 11-01-2024, 09:04 AM
RE: Ranks calculation - Albert Chan - 11-01-2024, 09:38 AM
RE: Ranks calculation - robmio - 11-01-2024, 10:03 AM
RE: Ranks calculation - Albert Chan - 11-01-2024, 10:34 AM
RE: Ranks calculation - robmio - 11-01-2024, 10:04 AM



User(s) browsing this thread: 3 Guest(s)