Homepage › Solution manuals › Gilbert Strang › Linear Algebra and Learning from Data › Exercise 1.2.8
Exercise 1.2.8
To compute by by , what order of the same three commands leads to columns times rows (outer products)?
Answers
To get columns times rows, we do:
- For to
- For to
- For to
#### Test the multiplication of columns times rows #### Test cases a = np.array([1,2]) b = np.array([3,4]) my_outer = mat.outer_product(a, b) np_outer = np.outer(a,b) assert(np.array_equal(my_outer, np_outer)) A = np.array([[1,2],[3,4]]) B = np.array([[2,1],[5,6]]) np_prod = np.matmul(A, B) my_prod_outer = mat.columns_times_rows_outer(A, B) my_prod_rc = mat.rows_times_columns(A, B) my_prod_cr = mat.columns_times_rows(A, B) assert(np.array_equal(my_prod_outer, np_prod)) assert(np.array_equal(my_prod_rc, np_prod)) assert(np.array_equal(my_prod_cr, np_prod)) A = np.array([[1,2],[3,4]]) B = np.array([[2],[5]]) mat.columns_times_rows(A, B)
array([[12.], [26.]])
2020-03-20 00:00