code optimized in IQR function

This commit is contained in:
Mitra-babu 2023-07-03 20:39:43 +05:30
parent 2b5d7c6095
commit ee3247bd1c

View File

@ -47,11 +47,9 @@ def inter_quartile_range(x: np.array) -> float:
if length == 0:
raise ValueError
x.sort()
q1 = find_median(x[0 : length // 2])
if length % 2:
q3 = find_median(x[(length // 2) + 1 : length])
else:
q3 = find_median(x[length // 2 : length])
q1 = find_median(x[0: length // 2])
half_length = (length // 2) + 1 if length % 2 else length // 2
q3 = find_median(x[half_length:length])
return q3 - q1