Python
Fundamentals
07/23/2025 09:37 PM 1
Agenda
• Recap
• Important Libiraries
• Numpy
• Matplotlib
• Pandas
• Seaborn
• Scipy
2
NumPy
• It’s the main library in python that deals with scientific computing, it
provides high performance multi-dimensional array
• So mainly it deals with arrays and metrices
1. How to create an array
• First: import the library
• [Link] which takes the numbers
• Ex: [Link]([1,2,3,4])
Getting the shape and type
• Arrays can be one dimensional or multidimensional so in order to
know that to know that you have to get the shape
• Array. Shape
• Type(array)
• This is for getting the type of an array
Change the values in the array
• Ex: array = [Link]([1,2,3,4])
• The index of the values starts from the zeroth element
• In order to access number 3 for example, then it is located at index 2
• To change it: array[2] = 7
• The new array now is [1,2,7,4]
Multi dimensional array
• Multi dimensional array means that it has more than one row and
Colum
• To create it: [Link]([ [10,20,30,40], [50,60,70,80] ])
• Now it is a 2d array
• To get the shape: array. Shape
• (2, 4) which means 2 rows and 4 columns
Indexing and slicing
• Ex: array = [Link]([[1,2,3], [7,8,9], [3,5,7]])
• For slicing: array[rows , columns] so
• array[0:2 , 1:3] ??
• Note: the first one is included, the second is excluded
Creating automatic arrays
• 1. zeros array
• 2. ones array
• 3. identity array
• 4. constant array
• 5. random array
Zeros & ones & constant
• Zeros: [Link]((shape of the array))
• Ones: [Link]((SHAPE OF THE ARRAY))
• Constant number: [Link]((SHAPE OF THE ARRAY),
(THE NUMBER) )
Identity Metrix
• To create it: [Link](the number of ones)
Random Metrix
• The most important one for machine and deep learning.
• [Link]((shape of the array))
• The numbers are randomly chosen and is between 0 and 1
• Used for initializing the weights in ml & dl
Argmax
• Argmax is a method that brings you the index of the highest values
• Ex: arr = [Link]([0.2, 0.4, 0.8])
print([Link] (arr) ) index 2 is the output
Note: this function is used mostly in deep learning (activation function
outputs)
Arithmetic operations
• [Link] (x, y) where x and y are arrays
• [Link] (x, y)
• [Link] (x, y)
• [Link] (x, y)
• [Link] (x)
• [Link] (x)
• [Link] (x)
2. matplotlib
• Used for data visualization and plotting graphs
•
Steps for data visualization
• 1. create the data (array of x & array of y)
• 2. plot the graph
• 3. give title
• 4. label the axis
• 5. name each plot
• 6. show the graph
Methods of matplotlib
• 1. [Link]
• 2. [Link]
• 3. [Link]
• 4. [Link]
• 5. [Link]
• 6. [Link]
• 7. [Link]
• 8. [Link]
PLOT & SCATTER & TITLE
Legends & subplot
subplots
import [Link] as plt
import numpy as np
x = [Link](1, 10, 20)
y = [Link](2, 30, 20)
z = [Link]([1,3,4,2,2,2,2,2,5,6,7,8,9,0,9,9,8,7,8,7])
fig, ((ax1, ax2), (ax3, ax4)) = [Link](2, 2, figsize=(15,15))
[Link](x, y, color = 'r')
[Link](x, z)
[Link](x, y)
[Link](x, z)
[Link]()
3. pandas
• Excel sheet for python.
• The most essential library for ml because it is where the data gets pre
processed.
• Clean the data by doing things like removing missing values and
filtering rows or columns by some criteria.
Primary Components of pandas
• 1. Series
• 2. Data frame
Creating data frame from
scratch
output
Index of the data frame
• The Index of this Data Frame was given to us on creation as the
numbers 0-3, but we could also create our own when we initialize
the Data Frame.
Access a specific index
Reading files with pandas
• Here comes the most important part in pandas
• 60% of The data which we are going to use through out the course are
coming from an excel sheet
• So in order to read it use the method [Link](‘path’)
Convert the data frame to an
array
• [Link]
Any Questions ?
30
Thank You ♥♥
31