Machine Learning- Section #3 (Numpy)
Machine Learning- Section #3 (Numpy)
In Python we have lists that serve the purpose of arrays, but they
are slow to process.
Arrays are very frequently used in data science, where speed and
resources are very important. 3
Why is NumPy Faster Than Lists?
5
NumPy as np
alias: In Python alias are an alternate name for referring to the same thing.
import numpy as np
print(arr)
6
NumPy vs Python Lists
0-D Arrays:
arr = np.array(42)
print(arr)
1-D Arrays:
# 2-D Arrays:
9
Arrays, creation
10
Arrays, creation
11
Array Indexing
13
Array Slicing
15
How to Transpose a Matrix in NumPy:
16
Arithmetic Operations:
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
# Element-wise addition
print("Addition:", a + b) # [5 7 9]
# Element-wise multiplication
print("Multiplication:", a * b) # [4 10 18]
# Element-wise division
print("Division:", a / b) # [0.25 0.4 0.5] 17
Logical Operators:
# Logical comparisons
c = np.array([10, 15, 20])
# Check equality
print("Equal to 15:", c == 15) # [False True False]
Code:
https://colab.research.google.com/drive/1oDldQj-
gMvtwqeb9RqFkOMSuQoDI3JrV?usp=sharing
20
Thank you for your
attention!
21