X-AI Practical File-2 (2024)
X-AI Practical File-2 (2024)
NB: If you submit any time after the deadline, you will not receive full credit
points
********************
10
DATA SCIENCE PROGRAMS
1 Write a program to create a 2D array using NumPy
Program:
import numpy as np
arr = np.arange(5,45,5)
arr = arr.reshape(2,4)
print(arr)
Output:
for i in range(n):
val=int(input("Enter value " + str(i+1) + ":" ))
l.append(val)
arr = np.array(l)
print("Array:",arr)
Output:
Page 11
3 Write a program to create a matrix of 3x3 from 11 to 30.
Program:
import numpy as np
arr = np.arange(11,28,2)
arr = arr.reshape(3,3)
print(arr)
Output:
4 Write a program to calculate variance and standard deviation for the given
data: [33,44,55,67,54,22,33,44,56,78,21,31,43,90,21,33,44,55,87]
Program:
import statistics
l=[33,44,55,67,54,22,33,44,56,78,21,31,43,90,21,33,44,55,87]
print("Variance:”, statistics.variance(l))
print("Standard Deviation:”, statistics.stdev(l))
Output:
5 Write a program to calculate the mean, mode and median for the given data:
[5,6,1,3,4,5,6,2,7,8,6,5,4,6,5,1,2,3,4]
Page 12
Program:
import statistics
l=[5,6,1,3,4,5,6,2,7,8,6,5,4,6,5,1,2,3,4]
Output:
Program:
import pandas as pd
d = { 'Name':['Anil','Bhavna','Chirag','Dhara','Giri'],
'Score':[25,20,22,23,21],
'Attempts':[1,2,2,1,1],
'Qualified':['Yes','No','Yes','Yes','No']
}
df = pd.DataFrame(d, index=['C001','C002','C003','C004','C005'] )
print(df)
Output:
Page 13
7 Write a program to create a dataframe named player and store their data in
the columns like team, no. of matches runs, and average. Assign player name
as row index and Display only those player details whose score is more than
1000.
Program:
import pandas as pd
d = { 'Team':['India','Pakistan','England','Australia'],
'Matches':[25,23,19,17],
'Runs':[1120,1087,954,830],
'Average':[44.80,47.26,50.21,48.82]
}
print(player[player['Runs']>1000])
Output:
Page 14
8 Write a program to represent the data on the ratings of mobile games on a bar
chart.
The sample data is given as: Games:Pubg, FreeFire, MineCraft, GTA-V, Call
of duty, FIFA 22. The rating for each game is as: 4.5,4.8,4.7,4.6,4.1,4.3.
Program:
Output:
Page 15
9 Write a program to represent the data given on a scatter plot chart.
Height (cm) = [120,145,130,155,160,135,150]
Weight (kg) = [40,50,47,62,60,55,58]
Program
Page 16
10 Consider the following data of a clothes store and plot the data on the line
chart and customize the chart as you wish:
Program:
import matplotlib.pyplot as pp
mon =['March','April','May','June','July','August']
jeans= [1500,3500,6500,6700,6000,6800]
ts = [4400,4500,5500,6000,5600,6300]
sh = [6500,5000,5800,6300,6200,4500]
pp.plot(mon,jeans,label='Mask',color='g',linestyle='dashed', linewidth=4,\
marker='o', markerfacecolor='k', markeredgecolor='r')
pp.plot(mon,ts,label='Mask',color='b',linestyle='dashed', linewidth=4,\
marker='3', markerfacecolor='k', markeredgecolor='g')
pp.plot(mon,sh,label='Mask',color='r',linestyle='dashed', linewidth=4,\
marker='v', markerfacecolor='k', markeredgecolor='b')
Output:
Page 17
11 Observe the given data for monthly sales of one of the salesmen for 6
months. Plot them on the line chart.
Program:
import matplotlib.pyplot as pp
mon = ['January','February','March','April','May','June']
sales = [2500,2100,1700,3500,3000,3800]
plt.plot(mon,sales,label='Sales',color='r',linestyle='dashed', linewidth=4,\
marker='o', markerfacecolor='k', markeredgecolor='b')
Page 18
plt.title("Sales Report")
plt.xlabel("Months")
plt.ylabel("Sales")
plt.legend()
plt.show()
Output:
12 Consider the following marks of students and plot the data on the histogram
and customize the chart as you wish:
Program:
Page 19
plt.ylabel("Count of Students")
plt.show()
Output:
Page 20
COMPUTER VISION PROGRAMS
1 On the basis of this online tool, try and write answers to all the below-mentioned questions.
Solution:
White
Yellow
Pink
Cyan
Black
Blue
Red
Green
R=0,G=0,B=255
2 Create your own pixels on piskelapp (https://www.piskelapp.com/) and make a gif image.
Solution:
Steps:
1. Open piskelapp on your browser.
2. Apply background for the picture.
3. Use pen to draw letter A
4. Copy the layer and paste it
5. Now erase letter A written previously
6. Apply the background colour for layer 2
7. Change the pen colour and Write I
8. Export the image.
9. Follow this link to access animated GIF: Click here
Page 21
3 Do the following tasks in OpenCV.
#Display Image
plt.imshow(img)
plt.title('Octopus')
plt.axis('off')
plt.show()
Page 22
2. Change the colour of image and Change the image to grayscale
#import required module cv2, matplotlib and numpy
import cv2
import matplotlib.pyplot as plt
import numpy as np
Page 23
#Changing image colour into gray image
image = cv2.imread('octopus.png')
cv2.imshow('Original',image)
grayscale = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
cv2.imshow('Grayscale', grayscale)
OUTPUT
Page 24
3. Print the shape of image
import cv2
img = cv2.imread('octopus.png',0)
print(img.shape)
OUTPUT:
(441, 453)
4. Display the maximum and minimum pixels of image
import cv2
img = cv2.imread('octopus.png',0)
print(img.min())
print(img.max())
OUTPUT
0
250
5. Crop the image and extract the part of an image
import cv2
import matplotlib.pyplot as plt
img = cv2.imread('octopus.png')
pi=img[150:400,100:200]
plt.imshow(cv2.cvtColor(pi, cv2.COLOR_BGR2RGB))
plt.title('Octopus')
plt.axis('off')
plt.show()
Page 25
6. Save the Image import cv2
Page 26