Question: import random def matrix _ generate ( n , m ) : Receives the number of rows n and number of columns
import random
def matrixgeneratenm:
Receives the number of rows n and number of columns m
and generates a matrix of size nbym with entries choosen as
random values in the range
The return matrix is stored as a listoflists"""
a random.randint for i in rangem for j in rangen
return a
def matrixchecka:
Given a matrix a check if each row has the same elements.
If corrent return True, else return False."""
nlena
mlena
for i in rangen:
if lenai m:
return False
return True
def matrixdisplaya:
Display the entries of a matrix as shown in the slides
This function has no return. It simply prints a
formatted view of the matrix.
nlena
mlena
out
for i in rangen:
out
for j in rangem:
out faij:
out
printout
def matrixsumab:
Given two matrices a and b check the size
of the matrices.
If the sizes match, calculate the sum of the matrices
and return the resulting matrix.
###############################
# Implement this function
###############################
return
def matrixtransposea:
Given a matrix A of size nxm
return the resulting matrix AT of size mxn
###############################
# Implement this function
###############################
return
def matrixissymmetrica:
Return True if the matrix is symmetric,
and False otherwise.
The matrix has to be square nbyn
and aij has to be same as aji
###############################
# Implement this function
##############################
return
if mainname:
#Let's create two by matrices
n
m
A matrixgeneratenm
B matrixgeneratenm
#Display the matrices
printMatrix A
matrixdisplayA
printMatrix B
matrixdisplayB
#Check the size of the matrices
printIs A a proper matrix?"
printmatrixcheckA
printIs B a proper matrix?"
printmatrixcheckB
######################################################
#Display the sum of the matrices
######################################################
#Uncomment these lines after implementing matrixsum
#printMatrix C AB
#C matrixsumAB
#matrixdisplayC
######################################################
#Uncomment these lines after implementing matrixtranspose
#printMatrix As transpose is:
#C matrixtransposeA
#matrixdisplayC
######################################################
#Uncomment the two print lines below after implementing
#matrixissymmmetric function
#Let create a x matrix
print
Let's create a by matrix and check if it is symmetric"
n
A matrixgeneratenn
matrixdisplayA
printIs this a symmetric matrix?"
#printissymmetricA
#Let's make the matrix symmetric
for i in rangen:
for j in rangein:
Aij Aji
matrixdisplayA
printIs this a symmetric matrix?"
#printissymmetricA
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
