Final answer:
To multiply two matrices and return their cross product in Python, you can write a function that uses nested loops to iterate over the rows and columns of the matrices.
Step-by-step explanation:
To write a function in Python to multiply two matrices and return their cross product, you can use nested loops to iterate over the rows and columns of the matrices. Here is an example of how the code could be implemented:
def matProd(matrix1, matrix2):
if len(matrix1[0]) != len(matrix2):
return 'Matrix sizes do not match'
else:
rows1 = len(matrix1)
cols1 = len(matrix1[0])
cols2 = len(matrix2[0])
result = [[0 for _ in range(cols2)] for _ in range(rows1)]
for i in range(rows1):
for j in range(cols2):
for k in range(cols1):
result[i][j] += matrix1[i][k] * matrix2[k][j]
return result
matrix1 = [[1, 2], [3, 4]]
matrix2 = [[5, 6], [7, 8]]
print(matProd(matrix1, matrix2))