Untitled

mail@pastecode.io avatar
unknown
plain_text
10 months ago
352 B
1
Indexable
Never
def matrix_multiply(A, B):
    m = len(A)
    n = len(A[0])
    p = len(B[0])

    if n != len(B):
        return "Invalid dimensions for matrix multiplication"

    C = [[0 for _ in range(p)] for _ in range(m)]

    for i in range(m):
        for j in range(p):
            for k in range(n):
                C[i][j] += A[i][k] * B[k][j]

    return C