Multiply two matrices together. If the number of columns in the first matrix does not equal the number of rows in the second, return -1.
def matrixmul(a: list[list[int|float]], b: list[list[int|float]]) -> list[list[int|float]]:
if len(a[0]) != len(b):
return -1
rows_a = len(a)
cols_b = len(b[0])
shared = len(b)
result = []
for i in range(rows_a):
row = []
for j in range(cols_b):
val = sum(a[i][k] * b[k][j] for k in range(shared))
row.append(val)
result.append(row)
return result