def percentileofscore(a, score, kind='rank'):
 a = np.array(a)
 n = len(a)
 if (kind == 'rank'):
  if (not np.any((a == score))):
   a = np.append(a, score)
   a_len = np.array(lrange(len(a)))
  else:
   a_len = (np.array(lrange(len(a))) + 1.0)
  a = np.sort(a)
  idx = [(a == score)]
  pct = ((np.mean(a_len[idx]) / n) * 100.0)
  return pct
 elif (kind == 'strict'):
  return ((sum((a < score)) / float(n)) * 100)
 elif (kind == 'weak'):
  return ((sum((a <= score)) / float(n)) * 100)
 elif (kind == 'mean'):
  return (((sum((a < score)) + sum((a <= score))) * 50) / float(n))
 else:
  raise ValueError("kind can only be 'rank', 'strict', 'weak' or 'mean'")

def percentileofscore ( a , score , kind = 'rank' ) : a = np . array ( a ) n = len ( a ) if ( kind == 'rank' ) : if ( not np . any ( ( a == score ) ) ) : a = np . append ( a , score ) a_len = np . array ( lrange ( len ( a ) ) ) else : a_len = ( np . array ( lrange ( len ( a ) ) ) + 1.0 ) a = np . sort ( a ) idx = [ ( a == score ) ] pct = ( ( np . mean ( a_len [ idx ] ) / n ) * 100.0 ) return pct elif ( kind == 'strict' ) : return ( ( sum ( ( a < score ) ) / float ( n ) ) * 100 ) elif ( kind == 'weak' ) : return ( ( sum ( ( a <= score ) ) / float ( n ) ) * 100 ) elif ( kind == 'mean' ) : return ( ( ( sum ( ( a < score ) ) + sum ( ( a <= score ) ) ) * 50 ) / float ( n ) ) else : raise ValueError ( "kind can only be 'rank', 'strict', 'weak' or 'mean'" )
return the percentile-position of score relative to data .