In: Computer Science
build a program which performs matrix multiplication on square matrices.
use UNIX "time" to capture the time it takes to run the program with different data sizes.
Languages: Python
Task: Create matrix multiplication
Input: Size of square matrix. Size should be 250, 500, 1000, 1500, 2000
Internals: Explicitly or implicitly allocate sufficient memory
to hold three NxN floating point Matrices,
using a random number generator -- populate two of the
Matrices,
Multiply the two matrices, putting the result into the third
Your routine should have not output
Externals: Your are to use UNIX "time" to time the runtime of the 5 experiments.
#source code:
import numpy as np
import time
start=time.time()
rand_250_A_matrix=np.random.randint(1,100,size=(250,250)) #generate
randomnumbers between 1 to 100 only
rand_250_B_matrix=np.random.randint(1,100,size=(250,250))
multiplication_of_250_matrix=np.matmul(rand_250_A_matrix,rand_250_B_matrix)
end=time.time()
print(multiplication_of_250_matrix)
Execution_time_of_250_sqare_matrix=end-start
start=time.time()
rand_500_A_matrix=np.random.randint(1,100,size=(500,500))
rand_500_B_matrix=np.random.randint(1,100,size=(500,500))
multiplication_of_500_matrix=np.matmul(rand_500_A_matrix,rand_500_B_matrix)
end=time.time()
print(multiplication_of_250_matrix)
Execution_time_of_500_sqare_matrix=end-start
start=time.time()
rand_1000_A_matrix=np.random.randint(1,100,size=(1000,1000))
rand_1000_B_matrix=np.random.randint(1,100,size=(1000,1000))
multiplication_of_1000_matrix=np.matmul(rand_1000_A_matrix,rand_1000_B_matrix)
end=time.time()
print(multiplication_of_1000_matrix)
Execution_time_of_1000_sqare_matrix=end-start
start=time.time()
rand_1500_A_matrix=np.random.randint(1,100,size=(1500,1500))
rand_1500_B_matrix=np.random.randint(1,100,size=(1500,1500))
multiplication_of_1500_matrix=np.matmul(rand_1500_A_matrix,rand_1500_B_matrix)
end=time.time()
print(multiplication_of_1500_matrix)
Execution_time_of_1500_sqare_matrix=end-start
start=time.time()
rand_2000_A_matrix=np.random.randint(1,100,size=(2000,2000))
rand_2000_B_matrix=np.random.randint(1,100,size=(2000,2000))
multiplication_of_2000_matrix=np.matmul(rand_2000_A_matrix,rand_2000_B_matrix)
end=time.time()
print(multiplication_of_2000_matrix)
Execution_time_of_2000_sqare_matrix=end-start
print("Execution time 250 square
matrix:",Execution_time_of_250_sqare_matrix)
print("Execution time 500 square
matrix:",Execution_time_of_500_sqare_matrix)
print("Execution time 1000 square
matrix:",Execution_time_of_1000_sqare_matrix)
print("Execution time 1500 square
matrix:",Execution_time_of_1500_sqare_matrix)
print("Execution time 2000 square
matrix:",Execution_time_of_2000_sqare_matrix)
#output:
#if you have any doubt comment below...