AI Lab Record for Class x
AI Lab Record for Class x
"""Question1: Draw a line chart with two lists X and Y with following values
x = [10,20,30,40,50]
y = [10,8,15,41,17] """
In [10]:
"""Question2: Draw a line chart with two lists X and Y with following values
x = [10,20,30,40,35]
y = ["a","b","c","d","e"]
and add plot(),show(),xlabel(), ylabel(), title() are called methods """
In [4]:
# question4: draw a scatter plot with x and y as array values
import matplotlib.pyplot as plt
import numpy as np
x = np.array([5,7,8,7,2,17,2,9,4,11,12,9,6] )
y = np.array([99,86,87,88,111,86,103,87,94,78,77,85,86])
#arrays can able to store sequence of homogeneous/similar type data
plt.scatter(x, y)
plt.xlabel("X-axis") # add X-axis label
plt.ylabel("Y-axis") # add Y-axis label
plt.title("X vs Y") # add title
plt.show()
In [3]:
"""Question5: Draw a bargraph with x and y array elements"""
In [12]:
"""Question 6:creating a bargraph with multicolor bars and multisize"""
In [11]:
""" Question 7. Draw a histogram for normal distribution curve"""
In [12]:
""" Question 8. Draw a histogram for an array of 100 random numbers,
with a range of 5 intervals"""
import matplotlib.pyplot as plt
import numpy as np
y=np.random.randn(100)
#random is module and randn is a method to display random values
nbins=5; #bins are intervals/groups
plt.hist(y,nbins,edgecolor="yellow")
plt.show()
In [14]:
""" Question 9. Draw a pie chart for an array of cars and mileage"""
In [1]:
""" Question 10. Draw a pie chart for an list of fruits and its calories"""
In [16]:
""" Question 12. display a picture by using imshow method and turn off axes """
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('d:\\meridian.jpg')
plt.imshow(img)
plt.axis('off')
plt.title("school logo")
plt.show()
In [27]:
""" Question 13. display a picture by using imshow method and turn off axes """
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('d:\\meridian.jpg' )
plt.imshow(img)
plt.axis('off')
plt.title("school logo")
plt.show()
In [33]:
""" Question 14. display a picture with normal colors and turn off axes """
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('d:\\meridian.jpg' )
plt.imshow(cv2.cvtColor(img,cv2.COLOR_BGR2RGB) )
plt.axis('off')
plt.title("school logo")
plt.show()
In [25]:
# Question 15. Write a program to read an image and identify its shape using Python
import cv2
from matplotlib import pyplot as plt
img = cv2.imread('e:\\tomandjerry.jpg' )
In [26]:
""" Question 16. write a python program to perform all arthmetic operations
on integer arrays """
import numpy as np
a=np.array([10,20,35,94,90,567])
b=np.array([1,2,3,4,90,87])
print(a+b)
print(a-b)
print(a*b)
print(a**b)
print(a%b)
[ 11 22 38 98 180 654]
[ 9 18 32 90 0 480]
[ 10 40 105 376 8100 49329]
[ 10 400 42875 78074896 0 110716871]
[ 0 0 2 2 0 45]
In [27]:
""" Question 17. write a python program to perform all mathematical
operations on integer arrays using functions """
import numpy as np
Sum of arrays:
[ 5 11 19 29 41]
Difference of arrays:
[ -3 -7 -13 -21 -31]
In [30]:
""" Question 18.Python program to check a given number is odd or
even."""
Enter a number: 58
58 is an Even number.
In [28]:
""" Question 19. Python program to find the largest number among three
different numbers:"""
# Input from the user
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
num3 = float(input("Enter the third number: "))
In [29]:
""" Question 20. python program to find the sum of first 20
natural numbers """
# Initialize variables
num = 1
sum = 0
In [2]:
"""Question 21.Python program to find the factorial of a number
provided by the user. """
factorial=1
# change the value for a different result
num = int(input("enter a number"))
enter a number8
The factorial of 8 is 40320
In [3]:
"""Question 22.Python program to display Multiplication table
(from 1 to 10) in Python """
In [ ]: