(mat1, mat2)
return mat3
Matrix multiplication (iterative algorithm).

    The running time of the iterative matrix multiplication algorithm is :math:`O(n^{3})`.

    :param mat1: 1st matrix with dimensions :math:`(n \\times p)`
    :type mat1: list, tuple
    :param mat2: 2nd matrix with dimensions :math:`(p \\times m)`
    :type mat2: list, tuple
    :return: resultant matrix with dimensions :math:`(n \\times m)`
    :rtype: list
Matrix multiplication (iterative algorithm).
Matrix multiplication ( iterative algorithm ) .
def matrix_multiply(mat1, mat2):
    """ Matrix multiplication (iterative algorithm).

    The running time of the iterative matrix multiplication algorithm is :math:`O(n^{3})`.

    :param mat1: 1st matrix with dimensions :math:`(n \\times p)`
    :type mat1: list, tuple
    :param mat2: 2nd matrix with dimensions :math:`(p \\times m)`
    :type mat2: list, tuple
    :return: resultant matrix with dimensions :math:`(n \\times m)`
    :rtype: list
    """
    n = len(mat1)
    p1 = len(mat1[0])
    p2 = len(mat2)
    if p1 != p2:
        raise GeomdlException("Column - row size mismatch")
    try:
        # Matrix - matrix multiplication
        m = len(mat2[0])
        mat3 = [[0.0 for _ in range(m)] for _ in range(n)]
        for i in range(n):
            for j in range(m):
                for k in range(p2):
                    mat3[i][j] += float(mat1[i][k] * mat2[k][j])
    except TypeError:
        # Matrix - vector multiplication
        mat3 = [0.0 for _ in range(n)]
        for i in range(n):
            for k in range(p2):
                mat3[i] += float(mat1[i][k] * mat2[k])
    return mat3
def matrix_multiply ( mat1 , mat2 ) : n = len ( mat1 ) p1 = len ( mat1 [ 0 ] ) p2 = len ( mat2 ) if p1 != p2 : raise GeomdlException ( "Column - row size mismatch" ) try : # Matrix - matrix multiplication m = len ( mat2 [ 0 ] ) mat3 = [ [ 0.0 for _ in range ( m ) ] for _ in range ( n ) ] for i in range ( n ) : for j in range ( m ) : for k in range ( p2 ) : mat3 [ i ] [ j ] += float ( mat1 [ i ] [ k ] * mat2 [ k ] [ j ] ) except TypeError : # Matrix - vector multiplication mat3 = [ 0.0 for _ in range ( n ) ] for i in range ( n ) : for k in range ( p2 ) : mat3 [ i ] += float ( mat1 [ i ] [ k ] * mat2 [ k ] ) return mat3