def apply_function_on_array(f, input_data):
    """Apply a function on input data.

    This method will apply a function on the input data.  If the input data
    is 1-d, it will expand the data to 2-d before feeding into the function,
    and then squeeze the output data back to 1-d if possible.

    Parameters
    ----------
    f : (np.ndarray) -> np.ndarray
        The function that will be applied to input data.

    input_data : np.ndarray
        The input data.

    Returns
    -------
    np.ndarray
    """
    # expand the input data to 2-d if it is 1-d
    if len(input_data.shape) == 1:
        input_data = input_data.reshape([-1, 1])
        ret = f(input_data)
        # revert back to 1-d if necessary.
        if len(ret.shape) == 2 and ret.shape[1] == 1:
            ret = ret.reshape([-1])
    else:
        ret = f(input_data)
    return ret