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
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()
Comments
Leave a comment