0% found this document useful (0 votes)
3 views6 pages

Class X Practical-2025 - Jupyter Notebook

The document provides an overview of NumPy, a scientific package for numerical computations in Python, detailing its array structures and mathematical operations. It also introduces Pandas for data manipulation, Matplotlib for data visualization, and OpenCV for image processing, including various examples of their usage. Key functions and methods for each library are demonstrated through code snippets.

Uploaded by

anuragkumarj744
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views6 pages

Class X Practical-2025 - Jupyter Notebook

The document provides an overview of NumPy, a scientific package for numerical computations in Python, detailing its array structures and mathematical operations. It also introduces Pandas for data manipulation, Matplotlib for data visualization, and OpenCV for image processing, including various examples of their usage. Key functions and methods for each library are demonstrated through code snippets.

Uploaded by

anuragkumarj744
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Numpy

NumPy is a powerful open-source scientific package that stands for Numerical Python. It uses
mathematical and logical operations for handling large datasets through n-dimensional arrays
that speeds up data processing.

ARRAYS - An ordered collection of values of


same data type that can be arranged in one or
more dimensions.
One dimensional array is called VECTOR
Two dimensional array is called MATRIX
An array with multiple dimension is called an n-dimensional array

In [ ]: import numpy as np

In [ ]: #One dimensional Array


a=np.array([3,4,6])
print(a)

In [ ]: #Two dimensional Array


a=np.array([[3,4,6],[7,5,4]])
print(a)

In [ ]: #Create a sequential 1 D array with values as multiples of 10 from 10 to 100


b=np.arange(10,101,10)
print(b)

In [ ]: a=np.ones((3,4))
print(a)

In [ ]: a=np.zeros((4,5))
print(a)

In [ ]: a=np.full((4,5),7)
print(a)

In [ ]: a=np.eye(4,4)
print(a)

Using Mathematical Operators on Integer


Array
In [ ]: a=np.array([1,2,4])
b=np.array([3,5,7])
print(a+b)
print(a-b)
print(a*b)
print(a/b)
print(a**2)
print(a//b)
print(a%b)

Some Important Functions


In [ ]: #type of an object
type(a)

In [ ]: #check the dimension of an array


c=np.array([[3,4,5,6],[5,8,6,4]])
print(c.ndim)

In [ ]: # length of array dimensions


print(c.shape)

In [ ]: #counts the number of elements


print(c.size)

In [ ]: # datatype of elements stored in the array


print(c.dtype)

In [ ]: #sort the array


d=np.array([6,34,22,26,74,36,64,38])
print(np.sort(d))

Statistical Functions
In [ ]: #maximum value in the element of the array
print(c.max())

In [ ]: #minimum value in the element of the array


print(c.min())

In [ ]: #sum of all the values in the given array


print(c.sum())
In [ ]: # prod- gives multiplication of array

m=np.array([4,2,3,9,7])
y=np.prod(m)
print(y)

In [ ]: # mean- gives average



y=np.mean(m)
print(y)

In [ ]: # median- gives middle value of array (first sorts and then gives middle value

m=np.array([4,2,3,9,7]) #as values are odd so gives centre value
y=np.median(m)
print(y)

In [ ]: m=np.array([4,2,3,6,9,7])
y=np.median(m) # as values are even so gives average of middle 2
print(y)

Pandas
Pandas is an open-source python library used for data manipulation and analysis

In [ ]: import pandas as pd

In [ ]: d1=pd.read_csv("Countrywise_coviddata.csv") #import data fil


print(d1.head()) #prints first 5

In [ ]: print(d1.head(10)) #prints the mentioned number of records

In [ ]: print(d1.tail()) #prints last 5 records

In [ ]: d2=d1.sort_values(by="Deaths", ascending=False) #ascending=True(Ascendin


print(d2.head(10))

In [ ]: d3=d1.drop(["Deaths","Confirmed","Active"], axis=1) #deletes the colu


print(d3.head())
d3.shape

In [ ]: #Isolate a column

d1["Recovered"]
In [ ]: #Isolate rows

d1[3:10]

Data Visualisaton

Matplotlib comes with various plotting modules


which provide an easy interface for creating 2
D plots
In [ ]: import numpy as np
import matplotlib.pyplot as plt

In [ ]: #Bar Plot

x=np.array(["Rohan", "Aarti", "Suniti", "Raghav", "Anshika"])
y=np.array([145,367,235,463,486])
plt.bar(x,y)
plt.show()

In [ ]: #Bar Plot

x=np.array(["Rohan", "Aarti", "Suniti", "Raghav", "Anshika"])
y=np.array([145,367,235,463,486])
plt.bar(x,y,color=["red","green","Blue","Orange","yellow"],edgecolor=['black',
plt.title("Result")
plt.xlabel("Names of the Students")
plt.ylabel("Marks")
plt.show()

 

In [ ]: #Scatter Plot

x=np.array(["Rohan", "Aarti", "Suniti", "Raghav", "Anshika"])
y=np.array([145,367,235,463,486])
plt.scatter(x,y)
plt.show()

In [ ]: #Line Plot

x=np.array(["Rohan", "Aarti", "Suniti", "Raghav", "Anshika"])
y=np.array([145,367,235,463,486])
plt.plot(x,y)
plt.show()
In [ ]: #Line Plot

x=np.array(["Rohan", "Aarti", "Suniti", "Raghav", "Anshika"])
y=np.array([145,367,235,463,486])
plt.plot(x,y,marker="*",ms=10, mec="red",mfc="green",linewidth=4,linestyle="do
plt.title("Result Comparison")
plt.xlabel("Name of the Students")
plt.ylabel("Marks")
plt.show()

In [ ]: #Pie Chart

m=np.array(['Soham','Raghav','Riya','Arjun'])
n=np.array([78,45,89,67])
plt.pie(y,labels=x)
plt.show()

In [ ]: #Histogram

a=[45,35,78,46,25,23,57,85,34,90,45,35,64,45]
plt.hist(a)
plt.show()

Image Processing

OpenCV stands for Open-Source Computer


Vision Library that helps the computer to
understand the content of digital images
In [ ]: import cv2

In [ ]: #Load Image File into Memory



img=cv2.imread('Shah.jpg')
plt.imshow(img) #Display Image on Graph
plt.axis('Off') # Hide X and Y Axis
plt.title('Shah Rukh')

OpenCV represents the images in BGR as opposed to the RGB we expect. Since it is in the
reverse order, you tend to see the blue color in images. We will use the following code for
converting from BGR to RGB

In [ ]: img1 = cv2.imread('Shah.jpg') #Load the image fil


plt.imshow(cv2.cvtColor(img1, cv2.COLOR_BGR2RGB))
plt.title('Shah Rukh') # Adds Title

In [ ]: img3=cv2.imread('shah.jpg')
gray=cv2.cvtColor(img3,cv2.COLOR_BGR2GRAY) #converts image int
plt.imshow(gray,cmap='gray')

In [ ]: # Check the size of Image



print(img3.shape)

In [ ]: # Resizing an Image
resized = cv2.resize(img, (360,640))
plt.imshow(cv2.cvtColor(resized, cv2.COLOR_BGR2RGB))
print(resized.shape)

In [ ]: # Flip an Image
img5=cv2.flip(img,0) # 0 - flip vertical, 1-
plt.imshow(img5)

In [ ]: imgcropped=img[500:650,200:900]
plt.imshow(imgcropped)

In [ ]: #Edge Detection

img9=cv2.imread('shah.jpg')
edge=cv2.Canny(img9, 200,200)
plt.imshow(edge)

In [ ]: #Saving an image to your system



cv2.imwrite('Gray.jpg',img9)

You might also like