Numpy_and_matplotlib_practical
Numpy_and_matplotlib_practical
In [5]: #alias
import numpy as np
print (np.__version__)
1.23.5
print(stu)
print(stu + 6)
print(stu * 2)
print(stu ** 3)
[2 4 6 7]
[ 8 10 12 13]
[ 4 8 12 14]
[ 8 64 216 343]
print(a)
print(a+5)
print(a ** 2)
[1 9 8 3]
[ 6 14 13 8]
[ 1 81 64 9]
(2, 4)
int32
In [5]: print(a.shape)
(4,)
print(arr1.dtype)
float64
In [8]: a = np.array([1,9,8,3,100])
print(a.max())
file:///C:/Users/deep2/OneDrive/Desktop/X_E_NUMPY_MATPLOTLIB.html 1/8
11/27/24, 12:15 PM X_E_NUMPY_MATPLOTLIB
100
In [9]: print(a.min())
In [10]: print(a.sum())
121
speed = [99,86,87,88,111,86,103,87,94,78,77,85,86]
avg_speed = np.mean(speed)
print(avg_speed)
89.76923076923077
print(med_speed)
87.0
speed = [99,86,87,88,111,86,103,87,94,78,77,85,86]
mode = stats.mode(speed)
arr = np.array(lst)
print(arr)
print(arr + 4)
print(lst +5)
[1 2 3 4 5]
[5 6 7 8 9]
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[11], line 8
5 print(arr)
7 print(arr + 4)
----> 8 print(lst +5)
file:///C:/Users/deep2/OneDrive/Desktop/X_E_NUMPY_MATPLOTLIB.html 2/8
11/27/24, 12:15 PM X_E_NUMPY_MATPLOTLIB
plt.plot(num,numbers)
plt.show()
# A bar chart or bar graph is a chart or graph that presents categorical data
#with rectangular bars with heights or lengths proportional to the values that
#they represent.
plt.bar(num,numbers)
plt.show()
file:///C:/Users/deep2/OneDrive/Desktop/X_E_NUMPY_MATPLOTLIB.html 3/8
11/27/24, 12:15 PM X_E_NUMPY_MATPLOTLIB
plt.hist(numbers)
plt.show()
file:///C:/Users/deep2/OneDrive/Desktop/X_E_NUMPY_MATPLOTLIB.html 4/8
11/27/24, 12:15 PM X_E_NUMPY_MATPLOTLIB
# create data
data = [32, 96, 45, 67, 76, 28, 79, 62, 43, 81, 70,
61, 95, 44, 60, 69, 71, 23, 69, 54, 76, 67,
82, 97, 26, 34, 18, 16, 59, 88, 29, 30, 66,
23, 65, 72, 20, 78, 49, 73, 62, 87, 37, 68,
81, 80, 77, 92, 81, 52, 43, 68, 71, 86]
# create histogram
plt.hist(data)
# display histogram
plt.show()
file:///C:/Users/deep2/OneDrive/Desktop/X_E_NUMPY_MATPLOTLIB.html 5/8
11/27/24, 12:15 PM X_E_NUMPY_MATPLOTLIB
x =[5, 7, 8, 7, 2, 17, 2, 9,
4, 11, 12, 9, 6]
plt.scatter(x, y, c ="blue")
file:///C:/Users/deep2/OneDrive/Desktop/X_E_NUMPY_MATPLOTLIB.html 6/8
11/27/24, 12:15 PM X_E_NUMPY_MATPLOTLIB
# dataset-1
x1 = [89, 43, 36, 36, 95, 10,
66, 34, 38, 20]
# dataset2
x2 = [26, 29, 48, 64, 6, 5,
36, 66, 72, 40]
plt.xlabel("deepshikha")
plt.ylabel("Y-axis")
plt.show()
file:///C:/Users/deep2/OneDrive/Desktop/X_E_NUMPY_MATPLOTLIB.html 7/8
11/27/24, 12:15 PM X_E_NUMPY_MATPLOTLIB
In [ ]:
file:///C:/Users/deep2/OneDrive/Desktop/X_E_NUMPY_MATPLOTLIB.html 8/8