Answer to Question #254038 in Python for shishi

Question #254038

Write a program in Python to perform the following operations on Matrix

using multithreading. Get the required input matrix from the user and after

that run three threads to perform the following operation.


a. Addition

b. Subtraction

c. Multiplication


1
Expert's answer
2021-10-20T18:36:51-0400
import threading
import numpy as np

def print_matrix():
    m = int(input('Enter no of rows here: '))
    n = int(input('Enter no of rows here: '))
    list1 = []
    m_n = m * n
    for i in range(m_n):
        j = int(input('Enter input here: '))
        list1.append(j)
    return np.array(list1).reshape(m, n)
def add_matrix(m,n):
    return m + n
def sub_matrix(m,n):
    return m - n
def mult_matrix(m,n):
    return m @ n
def main():
    m = print_matrix()
    n = print_matrix()
    add = add_matrix(m, n)
    sub = sub_matrix(m,n)
    prod = mult_matrix
    print(add)
    print(sub)
    print(prod)

if __name__ == "__main__":
    
    t1 = threading.Thread(target=add_matrix, args=(10,))
    t2 = threading.Thread(target=sub_matrix, args=(10,))
    t3 = threading.Thread(target=mult_matrix, args=(10,))
    
    t1.start()
    t2.start()
    t3.start()
    
    t1.join()
    t2.join()
    t3.join()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS