0% found this document useful (0 votes)
6 views

Practical No 13

The document contains practical exercises for Python programming, including matrix operations such as addition, subtraction, multiplication, and division using NumPy. It also includes a string concatenation example and a program to generate random integers. Each exercise is followed by the corresponding code and output demonstration.

Uploaded by

samarthn001
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Practical No 13

The document contains practical exercises for Python programming, including matrix operations such as addition, subtraction, multiplication, and division using NumPy. It also includes a string concatenation example and a program to generate random integers. Each exercise is followed by the corresponding code and output demonstration.

Uploaded by

samarthn001
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

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.

#Write a program to create two matrices and perform addition, subtra


ction, multiplication and division operations 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.

str1 = "Hello, Shantanu"


str2 = " Gaikwad"
str3 = str1 + str2
print("Concatenation Demo :- ",str3)

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 –

You might also like