Practical No 13
Practical No 13
X. Exercise
Que 1 - Write a Python program to create two matrices and perform addition, subtraction,
multiplication and division operation on matrix.
import numpy as np
x = [[1,1],[1,1]]
y = [[9,9],[9,9]]
#----------ADDITION----------
print("----------ADDITION----------")
result = [[0,0],[0,0]]
for i in range(len(x)):
for j in range(len(x[0])):
result[i][j] = x[i][j] + y[i][j]
print("Addition of Two Matrices :- ")
for r in result:
print(r)
#----------SUBTRACTION----------
print("----------SUBTRACTION----------")
result = [[0,0],[0,0]]
for i in range(len(x)):
for j in range(len(x[0])):
result[i][j] = x[i][j] - y[i][j]
print("Subtraction of Two Matrices :- ")
for r in result:
print(r)
#----------MULTIPLICATION----------
print("----------MULTIPLICATION----------")
result = [[0,0],[0,0]]
x1 = np.array(x)
y1 = np.array(y)
result = x1 @ y1
print("Multiplication of Two Matrices :- ")
for r in result:
print(r)
#----------DIVISION----------
print("----------DIVISION----------")
result = [[0,0],[0,0]]
x1 = np.array(x)
y1 = np.array(y)
result = np.true_divide(x1,y1)
print("Division of Two Matrices :- ")
for r in result:
print(r)
Output –
Que 2 - Write a Python program to concatenate two strings.
Output –
Que 3 - Write a NumPy program to generate six random integers between 10 and 30.
import numpy as np
x = np.random.randint(low = 10, high = 30, size = 6)
print(x)
Output –