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

Num Py

The document provides examples of using NumPy for accessing and slicing elements in 1-D and 2-D arrays, demonstrating specific outputs for each operation. It also includes examples of using Matplotlib to create various types of plots, including line diagrams, scatter plots, and plots with titles and labels. Each input is accompanied by its corresponding output, illustrating the functionality of the libraries.

Uploaded by

Akash Tomar
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)
13 views6 pages

Num Py

The document provides examples of using NumPy for accessing and slicing elements in 1-D and 2-D arrays, demonstrating specific outputs for each operation. It also includes examples of using Matplotlib to create various types of plots, including line diagrams, scatter plots, and plots with titles and labels. Each input is accompanied by its corresponding output, illustrating the functionality of the libraries.

Uploaded by

Akash Tomar
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

INPUT 1:
#Access elements from 2-D arrays

import numpy as np

arr=np.array([[1,2,3,4,5],[6,7,8,9,10]])

print("From 2-D",arr[0,1])

#Access elements from 3-D arrays

import numpy as np

arr=np.array([[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]]])

print("From 3-D",arr[0,1,2])

OUTPUT 1:
From 2-D 2

From 3-D 6

INPUT 2:
#Slicing Array in 1-D

import numpy as np

arr=np.array([1,2,3,4,5,6,7])

print("slicing in 1-D",arr[1:5])

#Slicing Array in 2-D

import numpy as np

arr=np.array([[1,2,3,4,5],[6,7,8,9,10]])

print("slicing in 2-D",arr[1,1:4])

OUTPUT 2:
slicing in 1-D [2 3 4 5]

slicing in 2-D [7 8 9]
Matplotlib
INPUT 1:
#Draw line diagram between two positions

import matplotlib.pyplot as plt

import numpy as np

xpoints = np.array([0,6])

ypoints = np.array([0,250])

plt.plot(xpoints,ypoints)

plt.show()

OUTPUT 1:

INPUT 2:
#Draw point without line

import matplotlib.pyplot as plt

import numpy as np
xpoints = np.array([1,8])

ypoints = np.array([3,10])

plt.plot(xpoints,ypoints,'o')

plt.show()

OUTPUT 2:

INPUT 3:
#Draw multiple points with different arguments

import matplotlib.pyplot as plt

import numpy as np

ypoints = np.array([3,8,1,10]) #Default xpoints

plt.plot(ypoints,marker='o',ms=20,mec='r',mfc='b')

plt.show()

OUTPUT 3:
INPUT 4:
#Draw multiple lines

import matplotlib.pyplot as plt

import numpy as np

y1=np.array([3,8,1,10])

y2=np.array([6,2,7,11])

plt.plot(y1)

plt.plot(y2)

plt.show()

OUTPUT 4:
INPUT 5:
#Draw plot with lables and title

import matplotlib.pyplot as plt

import numpy as np

x=np.array([80,85,90,95,100,105,110,115,120,125])

y=np.array([240,250,260,270,280,290,300,310,320,330])

plt.plot(x,y)

plt.title("Sports Watch Data")

plt.xlabel("Average Pulse")

plt.ylabel("Calorie Burnage")

plt.show()

OUTPUT 5:

You might also like