[Python (py3)] Using import numpy as np, import sys, and def functions Please create a code that solves for matrix addition, matrix scalar multiplication, and matrix multiplication The input will come from file1.txt, and the output should be printed to output.txt Note for matrix addition: When the dimension of Matrix A is not equal to the dimension of Matrix B, print "Matrix addition cannot be performed; dimensions are unequal." Note for matrix multiplication: When the number of columns of Matrix A is not equal to the number of rows of Matrix B, print "Matrix multiplication cannot be performed; number of columns of Matrix A is not equal to number of rows of Matrix B." Format of the input from file1.txt: First Line: type of operation (add or scalmultiply or multiply) Second Line: matrix A dimension (example: if 3 rows and 2 columns, type 3 2) Third Line: matrix A elements Fourth Line: matrix B dimension (or the scalar number for the operation of scalar multiplication) Fifth Line: matrix B elements (not needed for scalar multiplication) Sample input 1: add 2 2  53 -4 7 31 2 2 67 2 -34 6 Sample output 1: 120 -2 -27 37 Sample input 1.1: add 2 2  53 -4 7 31 2 3 67 2 1 -34 6 2 Sample Output 1.1: Matrix addition cannot be performed; dimensions are unequal. Sample input 2: scalMultiply 2 2 53 -4 7 31 2 Sample output 2: 106 -8 14 62 Sample input 3: multiply 3 3  34 10 3 7 8 34 6 2 12 3 2 1 2 3 4 5 6 Sample output 3: 79 126 201 250 72 92 Sample input 3.1: multiply 3 3  34 10 3 7 8 34 6 2 12 2 2 1 2 3 4 Sample output 3.1: Matrix multiplication cannot be performed; number of columns of Matrix A is not equal to number of rows of Matrix B.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

[Python (py3)]

Using import numpy as np, import sys, and def functions

Please create a code that solves for matrix addition, matrix scalar multiplication, and matrix multiplication

The input will come from file1.txt, and the output should be printed to output.txt

Note for matrix addition: When the dimension of Matrix A is not equal to the dimension of Matrix B, print "Matrix addition cannot be performed; dimensions are unequal."

Note for matrix multiplication: When the number of columns of Matrix A is not equal to the number of rows of Matrix B, print "Matrix multiplication cannot be performed; number of columns of Matrix A is not equal to number of rows of Matrix B."

Format of the input from file1.txt:
First Line: type of operation (add or scalmultiply or multiply)
Second Line: matrix A dimension (example: if 3 rows and 2 columns, type 3 2)
Third Line: matrix A elements
Fourth Line: matrix B dimension (or the scalar number for the operation of scalar multiplication)
Fifth Line: matrix B elements (not needed for scalar multiplication)

Sample input 1:
add
2 2 
53 -4
7 31
2 2
67 2
-34 6

Sample output 1:
120 -2
-27 37

Sample input 1.1:
add
2 2 
53 -4
7 31
2 3
67 2 1
-34 6 2

Sample Output 1.1:
Matrix addition cannot be performed; dimensions are unequal.

Sample input 2:
scalMultiply
2 2
53 -4
7 31
2

Sample output 2:
106 -8
14 62

Sample input 3:
multiply
3 3 
34 10 3
7 8 34
6 2 12
3 2
1 2
3 4
5 6

Sample output 3:
79 126
201 250
72 92

Sample input 3.1:
multiply
3 3 
34 10 3
7 8 34
6 2 12
2 2
1 2
3 4

Sample output 3.1:
Matrix multiplication cannot be performed; number of columns of Matrix A is not equal to number of rows of Matrix B.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education