
Complete this code using Python
m1 = [] #Matrix 1
m2 = [] #Matrix 2
#Write a function that will return the addition of Matrix A and B.
#Create a new matrix C that will hold the addtion result of Matrix A and B (A+B).
#Return the resultant matrix C
def addMatrix(A,B):
#Write your code here
#Write a function that will return the subtraction of Matrix B from A.
#Create a new matrix C that will hold the substraction result of Matrix B from A (A-B).
#Return the resultant matrix C
def subsMatrix(A,B):
#Write your code here
#Write a function that will return the multiplication of Matrix A and B.
#Create a new matrix C that will hold the multiplication result of Matrix A and B (A*B).
#Keep in mind,in order to perform matrix multiplication, the number of columns in Matrix A must be equal to the number of columns in Matrix B.
#Return the resultant matrix C
def multipyMatrix(A,B):
#Write your code here
#Write a function that will transform matrix A to the transpose of matrix A.
#The transpose of a matrix means the rows of the matrix will become the columns of the matrix, the columns will become rows of the matrix
def transpose(A):
#Write your code here
def takeRowColInput():
row = int(input("Please enter the number of rows in the matrix:"))
col = int(input("Please enter the number of columns in the matrix:"))
matrixInitialization(m1,row,col)
matrixInitialization(m2,row,col)
printMatrix(m1)
printMatrix(m2)
def matrixInitialization(m,row,col):
for r in range(row):
l=[]
for c in range(col):
l.append(0)
m.append(l)
def printMatrix(m):
for row in range(len(m)):
print("| ",end="")
for col in range(len(m[row])):
print(m[row][col], end =" ")
print("|")
print()
def takeMatrixInput(m):
for row in range(len(m)):
for col in range(len(m[row])):
m[row][col] = int(input(f"Enter value for [{row},{col}] : "))
printMatrix(m)
takeRowColInput()
takeMatrixInput(m1)
takeMatrixInput(m2)
addRes = addMatrix(m1,m2) #m1+m2
printMatrix(addRes)
subRes = subsMatrix(m1,m2) #m1-m2
printMatrix(subRes)
mulRes = multipyMatrix(m1,m2) #m1*m2
print(mulRes)
transpose(m1)
printMatrix(m1)
transpose(m2)
printMatrix(m2)

Step by stepSolved in 3 steps with 2 images

- /)9. Given an array of integers, write a PHP function to find the maximum element in the array. PHP Function Signature: phpCopy code function findMaxElement($arr) { // Your code here } Example: Input: [10, 4, 56, 32, 7] Output: 56 You can now implement the findMaxElement function to solve this problem. Keep it and.arrow_forwardCreate a function using Java: Number of Rows = 3-6 Number of Columns = 3-6 Function Name: ColumnWinParameters: board: 2D integer array, column: integer, piece: integerReturn: booleanAssume board is valid 2D int array, column is valid index in the board, piece is X==1/O==2Look at indicated column at given index in board. If that column has at least 3 consecutiveentries with given type of piece (X/O) (3 in a row XXX, OOO), then return true, otherwise false.arrow_forwardMatrix Addition• Write an addition function that accepts two 2D numpy arrays, andreturns the sum of the two (if they are the same size). This functionshould test that the arrays are the same size before performing theaddition. If the arrays are not the same size, the function shouldreturn -1. solve in pythonarrow_forward
- Write a complete C++ program that does the following: 3. Create a function called findSmallestValue which will return the smallest valuewithin the given 2d array.ex. If the findSmallestValue function was called using the array above, it wouldreturn 0.int findSmallestValue(int array[][6], int rows, int columns);4. Create a function called subtractAverage which calculates the average of theentries in a 2d array and subtracts this average from every entry of the array.void subtractAverage(int array[][6], int rows, int columns);5. Create a print function that prints every element in the 2d array. Print theentries of each row on their own line with spaces separating them.ex. If the print function was called using the array above, it would print asfollows:3 6 82 4 51 0 9void print(int array[][6], int rows, int columns);arrow_forwardON MATLAB PLSarrow_forwardQ2: In this question, you will write a Python function to compute the Hadamard product of two matrices. The Hadamard product is the "component-wise" product of two matrices. That is, each entry of the product matrix is equal to the product of its corresponding entries of the input matrices. Here is an example: a11 a12 a21 a22 a23 a31 a13 SH a32 033 A b11 b12 b13 b21 b22 b23 b31 b32 b33. B = [an bu a21 b21 a31 b31 a12 b12 a22 b22 a32 b32 a13 b13 a23 b23 a33 b33. Hadamard product of A and B Write a Python function to compute the Hadamard product of two matrices as follows. a) The inputs to the function are two matrices. b) The function should check whether the two matrices have the same size. If not, it should print "The input matrices are not of the same size". c) If two matrices are of the same size, the function computes the Hadamard product and returns the answer. Use for loops to compute the Hadamard product.arrow_forward
- Complete the following Codearrow_forwardCreate a function using Java: Number of Rows = 3-6 Number of Columns = 3-6 Function Name: winInDiagonalFSParameters: board: 2D integer array, piece: integerReturn: booleanAssume board is valid 2D int array, piece is X==1/O==2.Look at all forward slash / diagonals in the board. If any forward slash / diagonals has at least 3consecutive entries with given type of piece (X/O) (3 in a row XXX, OOO), then return true,otherwise falsearrow_forwardJava code Screenshot and output is mustarrow_forward
- 4A in Python language please:arrow_forward///////1/////. Given an array of integers, write a PHP function to find the maximum element in the array. PHP Function Signature: phpCopy code function findMaxElement($arr) { // Your code here } Example: Input: [10, 4, 56, 32, 7] Output: 56 You can now implement the findMaxElement function to solve this problem. Let me know answer. //. .arrow_forwardC++ Problem #1: Create a blank 10x10 integer array using constants for the row and column Create a function printArray() that will print every row and column of the array Create a function notFound() that searches each element in the array and returns true if the passed number already exists in the array and false if it does not Create a function fillArray() that will fill the 2 dimensional array with unique random numbers from 0 to 100 inclusive. No cells should have the same number. Use the notFound() function in this function. Print the entire array. Request a column number to print and use a sentinal loop to make sure the row number is valid. If not then request a column number again Create a function printIter() that prints only the passed column using iteration Create a function printRecur() that prints only the passed column using recursion Print the requested column using printIter() and printRecur() Sample output: The array is: Row 0: 41, 85, 72, 38, 80, 69, 65,…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





