generate functionTue, 28 Feb 2023

Matrix multiplication Write two functions that each multiply two square matrices, one without using numpy's built-in functions, and the other using numpy. The input to the first task is given lists of size size by size elements in each. The second task receives objects of type np.ndarray --- square matrices of the same size. The first function should return a list of lists, and the second should return np.array.

import numpy as np def multiply_matrices_without_numpy(list_a, list_b): # Write your code here n = len(list_a) c = [[0 for x in range(n)] for y in range(n)] for i in range(n): for j in range(n): for k in range(n): c[i][j] += list_a[i][k] * list_b[k][j] return c def multiply_matrices_with_numpy(array_a, array_b): # Write your code here return np.dot(array_a, array_b)

Questions about programming?Chat with your personal AI assistant