Python/OLS/ols_example/linalg.py
def check_2d(a, left_orient=True):
    """
    Make sure that the input is a 2D matrix.
    """

    # check that instance type is ndarray
    assert isinstance(a, np.ndarray), "Input must be an ndarray."

    # squeeze extra dimensions and convert to floats
    a = a.squeeze().astype(np.float64)

    # throw error if the matrix is empty
    if check_elements(a) == 0:
        raise Exception("Matrix is empty.")

    # reshape scalars to matricies
    if a.ndim == 0 and a.size == 1:
        if left_orient:
            return a.reshape(-1, 1)
        else:
            return a.reshape(1, -1)

    # reshape vectors to matricies
    if len(a.shape) == 1:
        if not left_orient:
            return a.reshape(-1, 1)
        else:
            return a.reshape(1, -1)

    # throw error if a tensor is input
    if len(a.shape) > 2:
        raise Exception("Matrix has too many dimensions.")

    return a

    Make sure that the input is a 2D matrix.
    
Make sure that the input is a 2D matrix.
Make sure that the input is a 2D matrix .
def check_2d(a, left_orient=True):
    assert isinstance(a, np.ndarray), "Input must be an ndarray."
    a = a.squeeze().astype(np.float64)
    if check_elements(a) == 0:
        raise Exception("Matrix is empty.")
    if a.ndim == 0 and a.size == 1:
        if left_orient:
            return a.reshape(-1, 1)
        else:
            return a.reshape(1, -1)
    if len(a.shape) == 1:
        if not left_orient:
            return a.reshape(-1, 1)
        else:
            return a.reshape(1, -1)
    if len(a.shape) > 2:
        raise Exception("Matrix has too many dimensions.")
    return a
def check_2d ( a , left_orient = True ) : assert isinstance ( a , np . ndarray ) , "Input must be an ndarray." a = a . squeeze ( ) . astype ( np . float64 ) if check_elements ( a ) == 0 : raise Exception ( "Matrix is empty." ) if a . ndim == 0 and a . size == 1 : if left_orient : return a . reshape ( - 1 , 1 ) else : return a . reshape ( 1 , - 1 ) if len ( a . shape ) == 1 : if not left_orient : return a . reshape ( - 1 , 1 ) else : return a . reshape ( 1 , - 1 ) if len ( a . shape ) > 2 : raise Exception ( "Matrix has too many dimensions." ) return a
Make sure that the input is a 2D matrix.
Make sure that the input is a 2D matrix .
"""
    Make sure that the input is a 2D matrix.
    """ # check that instance type is ndarray # squeeze extra dimensions and convert to floats # throw error if the matrix is empty # reshape scalars to matricies # reshape vectors to matricies # throw error if a tensor is input
a
left_orient