Matrix times Matrix

Multiply two matrices together (return -1 if shapes of matrix don't aline), i.e. C=AB

Example:

Input:

A = [[1, 2],[2, 4]], B = [[2, 1],[3, 4]]

Output:

[[8, 9],[16, 18]]

Reasoning:

1*2 + 2*3 = 8; 2*2 + 3*4 = 16; 1*1 + 2*4 = 9; 2*1 + 4*4 = 18 Example 2: input: A = [[1,2], [2,4]], B = [[2,1], [3,4], [4,5]] output: -1 reasoning: the length of the rows of A does not equal the column length of B

Code:

import numpy as np

def matrixmul(a, b):
    a = np.array(a)
    b = np.array(b)

    if a.shape[1] == b.shape[0]:
        return a @ b
    return -1