mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-25 10:28:39 +00:00
code optimized in IQR function
This commit is contained in:
parent
2b5d7c6095
commit
ee3247bd1c
@ -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
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user