mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-25 10:28:39 +00:00
Update maths/interquartile_range.py
Co-authored-by: Christian Clauss <cclauss@me.com>
This commit is contained in:
parent
14a3fb419d
commit
da1c06313e
@ -48,8 +48,9 @@ def interquartile_range(x: np.array) -> float:
|
|||||||
if length == 0:
|
if length == 0:
|
||||||
raise ValueError("The list is empty. Provide a non-empty list.")
|
raise ValueError("The list is empty. Provide a non-empty list.")
|
||||||
x.sort()
|
x.sort()
|
||||||
q1 = find_median(x[0 : length // 2])
|
div, mod = divmod(length, 2)
|
||||||
half_length = (length // 2) + 1 if length % 2 else length // 2
|
q1 = find_median(x[:div])
|
||||||
|
half_length = sum((div, mod))
|
||||||
q3 = find_median(x[half_length:length])
|
q3 = find_median(x[half_length:length])
|
||||||
return q3 - q1
|
return q3 - q1
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user