Num Py
Num Py
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])
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])
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 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 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 numpy as np
plt.plot(ypoints,marker='o',ms=20,mec='r',mfc='b')
plt.show()
OUTPUT 3:
INPUT 4:
#Draw multiple lines
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 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.xlabel("Average Pulse")
plt.ylabel("Calorie Burnage")
plt.show()
OUTPUT 5: