Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using PYTHON, answer the following (image below for details): matrix produet (xs

ID: 3878634 • Letter: U

Question

Using PYTHON, answer the following (image below for details):

matrix produet (xss,yss) given two "matrices" (lists of lists of integers), calculate and return their matrix product. You may assume that both matrices have values in them (they aren't size 0x0), but you do need to check that they have compatible dimensions; return None when they do not. matrix_product[1,2,3]], 4],15], (6]] 1 32]1 # order of arguments matters >>> matrix-product ( [[4],[5],[6]] , [[1,2,3]] ) [14, 8, 121, [5, 10, 151, [6, 12, 1811 matrix_product(11,2,13,4]],5,61,17,811 [[19, 22], [43, 5011 [[1,0],[0,1]], [[5,6],[7,8]] ) >>> matrix-product ( [[5, 61. 17. 811 >>matrix_product( [[1,0,01,10,1,0].[0,0,111. [11,2.31.14,5,61.17,8.911 1, 2, 31, [4, 5, 61, [7, 8, 911 S> >>> matrixproduct ( [[1,2]], [[1,2, 311 ) # gives back None.

Explanation / Answer

1)

import numpy as py
matrix1 = ([1,2,3])
matrix2 = ([4],[5],[6])
result = py.dot(matrix1, matrix2)
print "Matrix_product = ", result

OUTPUT

Matrix_product = [32]

2)

import numpy as py
matrix1 = ([4], [5], [6])
matrix2 = ([[1,2,3]])
result = py.dot(matrix1, matrix2)
print "matrix_product = ", result

OUTPUT

matrix_product = [[ 4 8 12]

[ 5 10 15]

[ 6 12 18]]

3)

import numpy as py
matrix1 = ([[1,2], [3,4]])
matrix2 = ([[5,6],[7,8]])
result = py.dot(matrix1, matrix2)
print "matrix_product = ", result

OUTPUT

matrix_product = [[19 22]

[43 50]]

4)

import numpy as py
matrix1 = ([[1,0], [0,1]])
matrix2 = ([[5,6],[7,8]])
result = py.dot(matrix1, matrix2)
print "matrix_product = ", result

OUTPUT

matrix_product = [[5 6]

[7 8]]

5)

import numpy as py
matrix1 = ([[1,0,0], [0,1,0],[0,0,1]])
matrix2 = ([[1,2,3],[5,6,7],[7,8,9]])
result = py.dot(matrix1, matrix2)
print "matrix_product = ", result

OUTPUT

matrix_product = [[1 2 3]

[5 6 7]

[7 8 9]]

6)

import numpy as py
matrix1 = ([[1,2]])
matrix2 = ([[1,2,3]])
result = py.dot(matrix1, matrix2)
print "matrix_product = ", result

OUTPUT

No Output

[Traceback (most recent call last):

File "main.py", line 9, in <module>

    res = np.dot(mat1,mat2)

ValueError: shapes (2,) and (3,) not aligned: 2 (dim 0) != 3 (dim 0)]

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote