def median(values):
    """Median function borrowed from python statistics module, and sped up by
    in-place sorting of the array.

    Args:
        data: Sequence of numeric values.

    Returns:
        The median (floating point).
    """
    datalen = len(values)
    if datalen == 0:
        raise ValueError("Cannot determine the median of an empty sequence")

    values.sort()

    idx = datalen // 2
    if datalen % 2 == 1:
        return values[idx]
    else:
        return (values[idx - 1] + values[idx]) / 2