Write the following Python script:
Imagine you live in a world without modules in Python! No numpy!No scipy! Write a Python script that defines afunction called mat_mult() thattakes two lists of lists as parameters and, when possible, returnsa list of lists representing the matrix product of the two inputs.Your function should make sure the lists are of the appropriatesize first - if not, your program should print “Invalid sizes†andreturn None. Note: it is actually tricky to make a useful list ofzeros. For instance, if you need to start with a 5 row, 6 columndouble list of 0, you might be tempted to try:
'''
thing = [ [ 0 ] ∗ 6 ] ∗ 5
'''
and if you look at it in the console window, it would appear tobe a 5 by 6 list of lists containing all zeros! However - try thefollowing and see what happens:
'''
thing [ 2 ] [ 5 ]
thing
'''
Notice that the item in index 5 of every row has changed, notjust the row with index 2! Given the difficulty, I will give youthe line of code that will create a list of lists that is num_rowsby num_cols:
'''
ans = [ [ 0 for col inrange ( num_cols ) ] for rowin range ( num_rows ) ]
'''
- The autograder will not allow numpy (or anything else!) to beimported
- Your solution will likely have a triple loop. Do some matrixmultiplications by hand for small and then larger matrices andfigure out what processes you are using. Code those.
- Given that your solution will likely have a triple loop, becareful with your indentation!
- As noted, trying to create an empty list of list of 0 can beproblematic since the interior lists are actually pointing to thesame information.