Can you write me a python program that allows a user to enter and validate their phone number and zipcode+4. Then the user will enter values of two, 3x3 matrices and then select from options including, addition, subtraction,  matrix multiplication, and element by element multiplication. You should use numpy.matmul() for  matrix multiplication (e.g. np.matmul(a, b) ). The program should compute the appropriate results  and return the results, the transpose of the results, the mean of the rows for the results, and the  mean of the columns for the results.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Can you write me a python program that allows a user to enter and validate their phone number and zipcode+4. Then the user will enter values of two, 3x3 matrices and then select from options including, addition, subtraction, 
matrix multiplication, and element by element multiplication. You should use numpy.matmul() for 
matrix multiplication (e.g. np.matmul(a, b) ). The program should compute the appropriate results 
and return the results, the transpose of the results, the mean of the rows for the results, and the 
mean of the columns for the results.

Expert Solution
Step 1

import numpy as np
import re
print("*******************************Welcome to the Python Matrix Application*******************")
while True:
print("Do you want to play the Matrix Game?")
#Reading the choice
choice=input("Enter Y for yes or N for No:")
if choice=="N":
print("****************Thanks for playing Python Numpy************************")
break
else:
while True:
phone=input("Enter your phone number(XXX-XXX-XXXX):")
#Regular expression for checking the phone number format
if not re.match("\d{3}-\d{3}-\d{4}",phone):
print("Your phone number is not in correct format. Please reenter:")
else:
break
while True:
zip=input("Enter your zipcode+4(XXXXX-XXXX):")
#Regular expression for checking the zipcode format
if not re.match("\d{5}-\d{4}",zip):
print("Your zipcode is not in correct format. Please reenter:")
else:
break
#Reading the first matrix
print("Enter your first 3x3 matrix:")
a=[]
for i in range(3):
#Reading row by row
row=input().split()
#Converting each element to integer
row=list(map(int,row))
#Adding row to the matrix
a.append(row)
#Printing first matrix
print("Your first 3x3 matrix is:")
for i in range(3):
for j in range(3):
print(a[i][j],end=" ")
print()
#Reading second matrix
print("Enter your second 3x3 matrix:")
b=[]
for i in range(3):
#Reading row by row
row=input().split()
#Converting each element to integer
row=list(map(int,row))
#Adding row to the matrix
b.append(row)
#Printing second matrix
print("Your second 3x3 matrix is:")
for i in range(3):
for j in range(3):
print(a[i][j],end=" ")
print()
#Menu for matrix operations   
print("Select a Matrix Operation from the list below:")
print("a. Addition")
print("b. Subtraction")
print("c. Matrix Multiplication")
print("d. Element by element multiplication")
ch=input()
if ch=="a":
print("You selected Addition. The results are:")
#converting list to numpy arrays
a=np.array(a)
b=np.array(b)
# addition of matrices
c=a+b
for i in range(3):
for j in range(3):
print(c[i][j],end=" ")
print()
print("The Transpose is:")
# function for finding the transpose
t=np.transpose(c)
for i in range(3):
for j in range(3):
print(t[i][j],end=" ")
print()
print("The row and column mean values of the results are:")
#Function mean with axis =1 finds row means
print("Row:",np.mean(c,axis=1))
#Function mean with axis =0 finds column means
print("Column:",np.mean(c,axis=0))
  
if ch=="b":
print("You selected Subtraction. The results are:")
a=np.array(a)
b=np.array(b)
# subtraction of matrices
c=a-b
for i in range(3):
for j in range(3):
print(c[i][j],end=" ")
print()
print("The Transpose is:")
# function for finding the transpose
t=np.transpose(c)
for i in range(3):
for j in range(3):
print(t[i][j],end=" ")
print()
print("The row and column mean values of the results are:")
#Function mean with axis =1 finds row means
print("Row:",np.mean(c,axis=1))
#Function mean with axis =0 finds column means
print("Column:",np.mean(c,axis=0))
  
if ch=="c":
print("You selected Matrix Multiplication. The results are:")
# For getting matrix multiplication use the function matrix instead of array in numpy
a=np.matrix(a)
b=np.matrix(b)
c=a*b
c=np.array(c)
for i in range(3):
for j in range(3):
print(c[i][j],end=" ")
print()
print("The Transpose is:")
# function for finding the transpose
np.transpose(c)
for i in range(3):
for j in range(3):
print(t[i][j],end=" ")
print()
print("The row and column mean values of the results are:")
#Function mean with axis =1 finds row means
print("Row:",np.mean(c,axis=1))
#Function mean with axis =0 finds column means
print("Column:",np.mean(c,axis=0))
  
if ch=="d":
print("You selected Element by Element Multiplication. The results are:")
a=np.array(a)
b=np.array(b)
# Elementary wise multiplication
c=a*b
for i in range(3):
for j in range(3):
print(c[i][j],end=" ")
print()
print("The Transpose is:")
# function for finding the transpose
t=np.transpose(c)
for i in range(3):
for j in range(3):
print(t[i][j],end=" ")
print()
print("The row and column mean values of the results are:")
#Function mean with axis =1 finds row means
print("Row:",np.mean(c,axis=1))
#Function mean with axis =0 finds column means
print("Column:",np.mean(c,axis=0))   

SCREENSHOT-

18 2. 20 main.py 1 #python code 2 limport numpy as np 3 import re 4 print(*** **Welcome to the Python Matrix Application* 5

44 45 46 47 48 49 50 51 52 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86

#Function mean with axis =@ finds column means print(Column:, np.mean(c, axis=0)) 87 88 89 90 91 92 93 94 95 96 97 98 99 10

print(t[i][jí, end=) print() print(The row and column mean values of the results are:) #Function mean with axis -1 finds

*****Welcome to the Python Matrix Application* Do you want to play the Matrix Game? Enter Y for yes or N for No:Y Enter your

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 5 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY