NumPy Tutorial 2
Concept: 1D vs 2D Arrays
In Machine Learning, a 1D Array is a list of numbers. A 2D Array (Matrix) is like an Excel sheet with rows and columns.
# Python "List of Lists"
matrix = [
[1, 2],
[3, 4]
]
# Hard to process columns
matrix = [
[1, 2],
[3, 4]
]
# Hard to process columns
import numpy as np
# NumPy 2D Array
matrix = np.array([
[1, 2],
[3, 4]
])
# print(matrix.shape)
# Output: (2, 2) -> 2 Rows, 2 Cols
# NumPy 2D Array
matrix = np.array([
[1, 2],
[3, 4]
])
# print(matrix.shape)
# Output: (2, 2) -> 2 Rows, 2 Cols
Activity: Build a Matrix
Drag the rows into the matrix container to build a 2x3 Array (2 Rows, 3 Columns).
Available Rows:
[10, 20, 30]
[40, 50, 60]
Matrix Container:
np.array([
Drop Row 1 Here
Drop Row 2 Here
])
Knowledge Check
If you have a NumPy array with 3 rows and 4 columns, what will array.shape return?
A. (4, 3)
B. (3, 4)
C. 12
0 Comments