median
median
dumbpy.median
Compute the median of numeric values.
The input may be a nested iterable; nesting is flattened via :func:dumbpy.support_functions.validate_list.
Functions
| Name | Description |
|---|---|
| median | Compute the median of numeric values. |
median
median.median(values)Compute the median of numeric values.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| values | Iterable[Any] | A (possibly nested) iterable containing numeric values. | required |
Returns
| Name | Type | Description |
|---|---|---|
| Numeric | float | The median value of the input after sorting. For odd-length inputs, the middle element is returned. For even-length inputs, the average of the two middle values is returned. |
Raises
| Name | Type | Description |
|---|---|---|
| ValueError | If the flattened input contains no elements. | |
| TypeError | If the input is not a valid iterable for flattening, or if any element is non-numeric (raised by :func:validate_list). |
Examples
>>> median([3, 1, 2])
2
>>> median([1, 2, 3, 4])
2.5