def _format_inputs(x):
    """Transform inputs into (m,n,1) format for cost/activation functions.
    Returns formatted array.

    """
    if x.ndim == 1:  # vector
        return x.reshape(1, -1, 1)
    elif x.ndim == 2:
        if x.shape[0] == 1:  # either single-row matrix or 1x1 matrix
            return x.T.reshape(1, -1, 1)
        else:  # multirow
            return x.reshape(x.shape[0], -1, 1)
    elif x.shape[1] == 1:  # mx1x1 or row-stacks
        return x.transpose((0, 2, 1))
    return x