Question

In: Computer Science

It is a strict requirement that this code is implemented in python. The code must be...

It is a strict requirement that this code is implemented in python. The code must be implemented from scratch not using e.g. numpy etc.

a. Create a function that takes a matrix X of all sizea as input and gives the transposed matrix as output. Example

transposeMatrix([[1,2]
          ,[3,4]
          ,[5,6]]) = [[1,3,5]
                      ,[2,4,6]]

b. Create a function that multilpies a matrix X1 and X2 of all sizes. Example

x1 = [[0,1]
     ,[1,0]
     ]
x2 = [[1, 0]
     ,[0,-1]
     ]
matrtixMultl(x1,x2) = [[0, -1]
                 ,[1,  0]
                 ]

c. Create a function that takes a square matrix as input and creates its inverse matrix as output. And that is such that matrixMult(A,matrixInvert(A)) is the unit matrix

Solutions

Expert Solution

Please find below the code, code screenshots and output screenshots. Please refer to the screenshot of the code to understand the indentation of the code.  Please get back to me if you need any change in code. Else please upvote.

Code for matrix transpose:

def transposeMatrix(matrix):

   

    print("The matrix is:")

    for row in matrix :

        print(row)

   

    # iterate through each element of matrix in column major manner and assign the value to result matrix    

    result = [[matrix[j][i] for j in range(len(matrix))] for i in range(len(matrix[0]))]

    print("\nThe transpose matrix is:")

    for row in result:

        print(row)

transposeMatrix([[1,2],[3,4],[5,6]])

Code for matrix multiplication:

def matrtixMultl(m1, m2):

   

    print("The matrixes are:")

    for row in m1 :

        print(row)

    print("\n")

    for row in m2 :

        print(row)

   

    result = [[sum(a*b for a,b in zip(m1_row,m2_col)) for m2_col in zip(*m2)] for m1_row in m1]

    print("\nThe result matrix after multiplication is:")

    for row in result:

        print(row)

x1 = [[0,1] ,[1,0]]

x2 = [[1, 0],[0,-1]]

matrtixMultl(x1,x2)


Related Solutions

write a python code that Returns a string composed of characters drawn, in strict alternation, from...
write a python code that Returns a string composed of characters drawn, in strict alternation, from s1 and s2. If one string is longer than the other, the excess characters are added to the end of the string as shown in the examples below #Example 1 - blend("ape", "BANANA") returns "aBpAeNANA" #Example 2 - blend("BOOT", "gold") returns "BgOoOlTd"
The Code of Ethics for Professional Accountants contains a specific requirement that must be met by...
The Code of Ethics for Professional Accountants contains a specific requirement that must be met by the incoming auditor when there is a change in appointment. State the requirement and the paragraph number in APES 110 for the requirement.
#python. Explain code script of each part using comments for the reader. The code script must...
#python. Explain code script of each part using comments for the reader. The code script must work without any errors or bugs. Ball moves in a 2D coordinate system beginning from the original point (0,0). The ball can move upwards, downwards, left and right using x and y coordinates. Code must ask the user for the destination (x2, y2) coordinate point by using the input x2 and y2 and the known current location, code can use the euclidean distance formula...
Could you modify my code so it meets the following requirement? (Python Flask) I want the...
Could you modify my code so it meets the following requirement? (Python Flask) I want the user to register for account using email and password, then store that data into a text file. Then I want the data to be read when logging in allowing the user to go to home page. -------------Code-------------------- routes.py from flask import Flask, render_template, redirect, url_for, request, session import json, re app = Flask(__name__) '''@app.before_request def before_request(): if 'visited' not in session: return render_template("login.html") else:...
*** Using Python *** Your program must prompt the user for their city or zip code...
*** Using Python *** Your program must prompt the user for their city or zip code and request weather forecast data from openweathermap.org. Your program must display the weather information in an READABLE format to the user. Requirements: Create a Python Application which asks the user for their zip code or city. Use the zip code or city name in order to obtain weather forecast data from: http://openweathermap.org/ Display the weather forecast in a readable format to the user. Use...
I need to implement a code in python to guess a random number. The number must...
I need to implement a code in python to guess a random number. The number must be an integer between 1 and 50 inclusive, using the module random function randint. The user will have four options to guess the number. For each one of the failed attempts, the program it should let the user know whether is with a lower or higher number and how many tries they have left. If the user guess the number, the program must congratulate...
The code that creates this program using Python: Your program must include: You will generate a...
The code that creates this program using Python: Your program must include: You will generate a random number between 1 and 100 You will repeatedly ask the user to guess a number between 1 and 100 until they guess the random number. When their guess is too high – let them know When their guess is too low – let them know If they use more than 5 guesses, tell them they lose, you only get 5 guesses. And stop...
Answer as soon as possible!!! Code must be done with Python Develop a basic File Transfer...
Answer as soon as possible!!! Code must be done with Python Develop a basic File Transfer Protocol (FTP) application that transmits files between a client and a server using Python. Your programs should implement four FTP commands: (1) change directory (cd), (2) list directory content (ls), (3) copy a file from client to a server (put) and (4) copy a file from a server to a client (get). Implement two versions of the program: one that uses stock TCP for...
THE CODE MUST BE PYTHON superHeroes = { "MoleculeMan": { "age": 29, "secretIdentity": "Dan Jukes", "superpowers":...
THE CODE MUST BE PYTHON superHeroes = { "MoleculeMan": { "age": 29, "secretIdentity": "Dan Jukes", "superpowers": [ "Radiation Immunity", "Turning tiny", "Radiation blast" ] }, "MadameUppercut": { "age": 39, "secretIdentity": "Jane Wilson", "superpowers": [ "Million tonne punch", "Damage resistance", "Superhuman reflexes" ] }, "EternalFlame": { "age": 1000, "secretIdentity": "Unknown", "superpowers": [ "Immortality", "Heat Immunity", "Inferno", "Teleportation", "Interdimensional travel" ] }, "Doomguy": { "age": 27, "secretIdentity": "Space Trooper", "superpowers": [ "Immortality", "Heat Immunity", "Teleportation", "Super Speed", "Superhuman reflexes" ] }, "Maui":{...
Using python, produce code that mimics some ATM transactions: a. A welcome message must be displayed...
Using python, produce code that mimics some ATM transactions: a. A welcome message must be displayed initially reflecting the appropriate time of day (for example: Good Night, Welcome to Sussex Bank). b. Assume the user’s account balance is $5375.27. c. Allow the user to enter a pin number that does not have to be validated: def atm_login(): pin_number = input("Please enter your (4 digit) pin number: ") # display welcome message welcome_message() d. The message should be followed by a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT