IQR function is added

This commit is contained in:
Mitra-babu 2023-07-02 20:23:58 +05:30
parent 483d59adec
commit aa5dccb6b8

View File

@ -8,18 +8,18 @@ Script inspired from its corresponding Wikipedia article
https://en.wikipedia.org/wiki/Interquartile_range https://en.wikipedia.org/wiki/Interquartile_range
""" """
from typing import List import numpy as np
def find_median(x: List[float]) -> float: def find_median(x: np.array) -> float:
""" """
This is the implementation of median. This is the implementation of median.
:param x: The list of numeric values :param x: The list of numeric values
:return: Median of the list :return: Median of the list
>>> find_median([1,2,2,3,4]) >>> find_median(x=np.array([1,2,2,3,4]))
2 2
>>> find_median([1,2,2,3,4,4]) >>> find_median(np.array([1,2,2,3,4,4]))
2.5 2.5
@ -30,17 +30,17 @@ def find_median(x: List[float]) -> float:
return float((x[length // 2] + x[(length // 2) - 1]) / 2) return float((x[length // 2] + x[(length // 2) - 1]) / 2)
def inter_quartile_range(x: List[float]) -> float: def inter_quartile_range(x: np.array) -> float:
""" """
This is the implementation of inter_quartile This is the implementation of inter_quartile
range for a list of numeric. range for a list of numeric.
:param x: The list of data point :param x: The list of data point
:return: Inter_quartile range :return: Inter_quartile range
>>> inter_quartile_range([4,1,2,3,2]) >>> inter_quartile_range(x=np.array([4,1,2,3,2]))
2.0 2.0
>>> inter_quartile_range([25,32,49,21,37,43,27,45,31]) >>> inter_quartile_range(x=np.array([25,32,49,21,37,43,27,45,31]))
18.0 18.0
""" """
length = len(x) length = len(x)