Launch the interactive walkthrough to discover each component, including the 3D Q-Sphere Lab & Python in Colab.
Understand why Python is the undisputed lingua franca of AI, and survey essential tools: NumPy, Pandas, Matplotlib, Scikit-Learn, and PyTorch.
| Symbol / Term | Meaning | Beginner Interpretation |
|---|---|---|
| Input matrices | Feature activations and network weights | |
| Resultant matrix | Output tensor of transformed features |
Multiplying 1x2 row vector [2, 3] by 2x1 column vector [[4], [5]].
Result: Scalar product: 23
Read CSV, JSON, or SQL database into structured DataFrame.
Extract numerical matrices and normalize tensor values.
Pass arrays into GPU/CPU tensors to fit weights.
Plot loss curves and confusion matrices to audit performance.
Problem: Cleaning dirty corporate datasets containing missing values.
Solution: Pandas handles missing imputation, date parsing, and one-hot encoding in seconds.
Problem: Training large neural networks on 10 million images.
Solution: PyTorch tensors execute parallel matrix multiplications across NVIDIA GPU clusters.
Interactive activity component
Master core numerical and tabular data handling with NumPy arrays, matrix reshaping, random generation, and Pandas DataFrame manipulation.
For Google Colab or Jupyter notebooks, run this shell command to install the required dependencies:
!pip install numpy pandas1 import numpy as np 2 import pandas as pd
import numpy as np โ Core library for numerical arrays and vectorized linear algebra
import pandas as pd โ High-performance DataFrame data structures for tabular data
1 # --- Part 1: NumPy Array Creation & Operations (Lesson 4.1) --- 2 arr = np.array([1, 2, 3, 4, 5]) 3 print("NumPy Array:", arr) 4 print("Reshaped 5x1 Matrix: 5 ", arr.reshape(5, 1)) 6 print("Squared Array Elements:", arr ** 2) 7 random_matrix = np.random.rand(3, 3) 8 print("Random 3x3 Matrix: 9 ", random_matrix.round(3)) 10 11 # --- Part 2: Pandas DataFrames & Statistics (Lesson 4.2) --- 12 data = { 13 "Name": ["Alice", "Bob", "Charlie"], 14 "Age": [25, 30, 35], 15 "Salary": [50000, 60000, 70000] 16 } 17 df = pd.DataFrame(data) 18 print(" 19 Pandas DataFrame: 20 ", df) 21 print(" 22 Descriptive Statistics: 23 ", df.describe()) 24 filtered_df = df[df["Age"] > 30] 25 print(" 26 Employees with Age > 30: 27 ", filtered_df)
# --- Part 1: NumPy Array Creation & Operations (Lesson 4.1) ---
Section header
arr = np.array([1, 2, 3, 4, 5])
Create a 1D NumPy array
print("NumPy Array:", arr)
Display array elements
print("Reshaped 5x1 Matrix: ", arr.reshape(5, 1))
Reshape into 2D column matrix
print("Squared Array Elements:", arr ** 2)
Vectorized element-wise exponentiation
random_matrix = np.random.rand(3, 3)
Generate a 3x3 matrix of uniform random floats
print("Random 3x3 Matrix: ", random_matrix.round(3))
Display random matrix
# --- Part 2: Pandas DataFrames & Statistics (Lesson 4.2) ---
Section header
data = {
Construct sample dictionary
"Name": ["Alice", "Bob", "Charlie"],
Categorical string column
"Age": [25, 30, 35],
Numerical integer column
"Salary": [50000, 60000, 70000]
Numerical salary column
}
Close dictionary
df = pd.DataFrame(data)
Create structured Pandas DataFrame
print(" Pandas DataFrame: ", df)
Display tabular DataFrame
print(" Descriptive Statistics: ", df.describe())
Compute summary metrics (mean, std, min, max)
filtered_df = df[df["Age"] > 30]
Filter rows based on condition Age > 30
print(" Employees with Age > 30: ", filtered_df)
Display filtered subset
Click "Copy for Colab", open Google Colab, paste into a single cell, and run.
1 # ========================================================= 2 # Lesson 4: Python Data Foundations โ NumPy Arrays & Pandas DataFrames 3 # Prepared for Google Colab (Run with Shift + Enter) 4 # ========================================================= 5 6 # Step 1: Install required packages 7 !pip install numpy pandas 8 9 # Step 2: Import libraries 10 import numpy as np 11 import pandas as pd 12 13 # Step 3: Run Demonstration 14 # --- Part 1: NumPy Array Creation & Operations (Lesson 4.1) --- 15 arr = np.array([1, 2, 3, 4, 5]) 16 print("NumPy Array:", arr) 17 print("Reshaped 5x1 Matrix: 18 ", arr.reshape(5, 1)) 19 print("Squared Array Elements:", arr ** 2) 20 random_matrix = np.random.rand(3, 3) 21 print("Random 3x3 Matrix: 22 ", random_matrix.round(3)) 23 24 # --- Part 2: Pandas DataFrames & Statistics (Lesson 4.2) --- 25 data = { 26 "Name": ["Alice", "Bob", "Charlie"], 27 "Age": [25, 30, 35], 28 "Salary": [50000, 60000, 70000] 29 } 30 df = pd.DataFrame(data) 31 print(" 32 Pandas DataFrame: 33 ", df) 34 print(" 35 Descriptive Statistics: 36 ", df.describe()) 37 filtered_df = df[df["Age"] > 30] 38 print(" 39 Employees with Age > 30: 40 ", filtered_df)
Instantiate and reshape contiguous numerical vectors.
Perform instant C-level element-wise squaring without slow Python for-loops.
Load structured records into an indexed Pandas DataFrame.
Compute summary statistics and execute conditional row filtering.
NumPy array [1,2,3,4,5] and Employee dictionary {Name, Age, Salary}Array: [1 2 3 4 5] Squared: [ 1 4 9 16 25] Mean Age: 30.0, Mean Salary: $60,000 Employees > 30: Charlie (Age 35, Salary $70,000)
NumPy provides the high-speed numerical array backend, while Pandas enables clean tabular data wrangling โ forming the indispensable data foundation for all AI and quantum preprocessing pipelines.
NumPy, pandas, preprocessing, and classification pipelines โ Presentation by Dr. Syed Muzamil Basha.
Test your understanding with these questions. Remember, this is for learning, not examination!