def findMedian(x):
    """Compute the median of x.

    Parameters
    ----------
    x: array_like
        An array that can be sorted.

    Returns
    -------
    median_x: float
        If there are an odd number of elements in x, median_x is the
        middle element; otherwise, median_x is the average of the two
        middle elements.
    """

    nelem = len(x)
    middle = nelem // 2
    if middle * 2 < nelem:
        odd = True
    else:
        odd = False
    index = x.argsort()
    if odd:
        median_x = x[index[middle]]
    else:
        median_x = (x[index[middle]-1] + x[index[middle]]) / 2.

    return median_x