20 lines
464 B
Python
20 lines
464 B
Python
import numpy as np
|
|
|
|
R = np.array([720, 740, 760, 780, 800, 820])
|
|
A = np.array([19, 24, 26, 27, 10, 5])
|
|
B = np.array([4, 8, 52, 40, 32, 24])
|
|
|
|
def qval(edges, counts, x):
|
|
cdf = np.cumsum(counts) / counts.sum()
|
|
i = np.searchsorted(edges, x)
|
|
if i == 0: return 0.0
|
|
if i >= len(edges): return 1.0
|
|
w = edges[1] - edges[0]
|
|
return cdf[i-1] + (x - edges[i-1]) / w * (cdf[i] - cdf[i-1])
|
|
|
|
qa = qval(R, A, 730)
|
|
qb = qval(R, B, 750)
|
|
|
|
print(qa)
|
|
print(qb)
|