11/27/24, 12:15 PM X_E_NUMPY_MATPLOTLIB
In [5]: #alias
import numpy as np
print (np.__version__)
1.23.5
In [21]: #CREATING AN ARRAY USING NUMPY
stu = [Link]([2,4,6,7])
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]
In [4]: a = [Link]([1,9,8,3]) #1d dimension
print(a)
print(a+5)
print(a ** 2)
[1 9 8 3]
[ 6 14 13 8]
[ 1 81 64 9]
In [3]: import numpy as npy
# creating a 2-d array
arr1 = [Link]([[1, 3, 5,7 ], [2, 4, 6, 8]])
print([Link])
print([Link])
(2, 4)
int32
In [5]: print([Link])
(4,)
In [26]: arr1 = [Link]([1.2, 4.5, 7.8])
print([Link])
float64
In [8]: a = [Link]([1,9,8,3,100])
print([Link]())
[Link] 1/8
11/27/24, 12:15 PM X_E_NUMPY_MATPLOTLIB
100
In [9]: print([Link]())
In [10]: print([Link]())
121
In [34]: #STATISTICAL - MEAN, MEDIAN, MODE
speed = [99,86,87,88,111,86,103,87,94,78,77,85,86]
avg_speed = [Link](speed)
print(avg_speed)
89.76923076923077
In [11]: med_speed = [Link](speed)
print(med_speed)
87.0
In [15]: from scipy import stats
speed = [99,86,87,88,111,86,103,87,94,78,77,85,86]
mode = [Link](speed)
C:\Users\deep2\AppData\Local\Temp\ipykernel_8704\[Link]: FutureWarning: Unlik
e other reduction functions (e.g. `skew`, `kurtosis`), the default behavior of `mode`
typically preserves the axis it acts along. In SciPy 1.11.0, this behavior will chang
e: the default value of `keepdims` will become False, the `axis` over which the stati
stic is taken will be eliminated, and the value None will no longer be accepted. Set
`keepdims` to True or False to avoid this warning.
mode = [Link](speed)
In [11]: lst = [1,2,3,4,5]
arr = [Link](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)
TypeError: can only concatenate list (not "int") to list
[Link] 2/8
11/27/24, 12:15 PM X_E_NUMPY_MATPLOTLIB
MATPLOTLIB - VISUALIZATION LIBRAY OF
PYTHON
In [38]: from matplotlib import pyplot as plt
# A line plot is a way to display data along a number line.
flavors = ['orange', 'vanilla', 'chocolate', 'mint', 'mango']
numbers = [5, 2, 9, 4, 7]
num = [15, 12, 10, 9, 7]
[Link](num,numbers)
[Link]()
In [39]: from matplotlib import pyplot as plt
# 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.
flavors = ['orange', 'vanilla', 'chocolate', 'mint', 'mango']
numbers = [5, 2, 9, 4, 7]
#num = [15, 12, 10, 9, 7]
[Link](num,numbers)
[Link]()
[Link] 3/8
11/27/24, 12:15 PM X_E_NUMPY_MATPLOTLIB
In [40]: #Plotting a Histogram
#A histogram is a graphical representation of a grouped frequency
#distribution with continuous classes
flavors = ['orange', 'vanilla', 'chocolate', 'mint', 'mango']
numbers = [5, 2, 9, 4, 7]
#num = [15, 12, 10, 9, 7]
[Link](numbers)
[Link]()
[Link] 4/8
11/27/24, 12:15 PM X_E_NUMPY_MATPLOTLIB
In [41]: import [Link] as plt
# 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
[Link](data)
# display histogram
[Link]()
[Link] 5/8
11/27/24, 12:15 PM X_E_NUMPY_MATPLOTLIB
In [42]: # A scatter plot is a type of plot or mathematical diagram using Cartesian
#coordinates to display values for typically two variables for a set of data.
In [43]: import [Link] as plt
x =[5, 7, 8, 7, 2, 17, 2, 9,
4, 11, 12, 9, 6]
y =[99, 86, 87, 88, 100, 86,
103, 87, 94, 78, 77, 85, 86]
[Link](x, y, c ="blue")
# To show the plot
[Link]()
[Link] 6/8
11/27/24, 12:15 PM X_E_NUMPY_MATPLOTLIB
In [46]: import [Link] as plt
# dataset-1
x1 = [89, 43, 36, 36, 95, 10,
66, 34, 38, 20]
y1 = [21, 46, 3, 35, 67, 95,
53, 72, 58, 10]
# dataset2
x2 = [26, 29, 48, 64, 6, 5,
36, 66, 72, 40]
y2 = [26, 34, 90, 33, 38,
20, 56, 2, 47, 15]
[Link](x1, y1, c ="pink",
linewidths = 2,
marker ="s",
edgecolor ="green",
s = 50)
[Link](x2, y2, c ="yellow",
linewidths = 2,
marker ="^",
edgecolor ="pink",
s = 200)
[Link]("deepshikha")
[Link]("Y-axis")
[Link]()
[Link] 7/8
11/27/24, 12:15 PM X_E_NUMPY_MATPLOTLIB
In [ ]:
[Link] 8/8