Page 499 - AI Ver 3.0 class 10_Flipbook
P. 499

22.  Using NumPy package: Create an array of 5 marks and display the average of all marks.


                  Ans.  [1]:  import numpy as np
                             import statistics
                             a = np.array([95,90,49,71,80])
                             m = statistics.mean(a)
                             print("The average is: ", m)
                             The average is:  77

                   23.  Create a list of number of voting done in 6 areas and calculate using statistics module:

                       Standard deviation
                       Variance

                  Ans.  [1]:  import statistics
                             votes = [59, 52, 49, 71, 44, 63]
                             std_dev = statistics.stdev(votes)
                             print("The standard deviation is:", round(std_dev, 2))
                             variance = statistics.variance(votes)
                             print("The variance is:", variance)

                             The standard deviation is: 9.91
                             The variance is: 98.26666666666667

                   24.  Using the library: import cv2, matplotlib

                       Upload an image of your favourite food and display the picture in RGB color mode.

                  Ans.  [1]:  import cv2
                             from matplotlib import pyplot as plt
                             import numpy as np
                             img = cv2.imread('D:/Pasta.jpg')
                             plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
                             plt.title('My Favourite Food')
                             plt.axis('off')
                             plt.show

                             <function matplotlib.pyplot.show(close=None, block=None)>
                                                            My Favourite Food




















                   25.  Using the library: import cv2, matplotlib
                       Upload an image of your favourite pet and display the picture in grayscale mode.





                                                                                    Python Practical Questions  497
   494   495   496   497   498   499   500   501   502   503   504