2. NumPy
NumPy provides efficient multidimensional arrays.
import numpy as np
x = np.array([1, 2, 3])
Important properties
x.shape
x.ndim
x.size
x.dtype
Matrix:
X = np.array([
[1, 2, 3],
[4, 5, 6]
])
Shape:
(2, 3)
2 rows
3 columns
Vectorized operations
x * 2
x + 5
x.mean()
x.sum()
Prefer vectorized operations over manually looping through every value when possible.
ML convention
X.shape = (samples, features)
Example:
(1000, 10)
1000 samples
10 features each
3. Pandas
Pandas is useful for working with tabular data.
import pandas as pd
df = pd.read_csv("customers.csv")
Inspect data
df.head()
df.tail()
df.shape
df.columns
df.dtypes
df.info()
df.describe()
Missing values:
df.isna().sum()
Select column:
df["age"]
Multiple columns:
df[["age", "income"]]
Filter:
df[df["age"] >= 18]
loc vs iloc
df.loc[...] # label-based
df.iloc[...] # position-based
DataFrame vs Series
DataFrame → table / multiple columns
Series → usually one column
ML convention
X = df.drop(columns=["target"])
y = df["target"]
X = input features
y = target/answer
4. Jupyter Notebooks
Notebook files:
.ipynb
They contain: - code cells - Markdown cells - outputs
Good for: - exploration - visualization - experiments - learning - EDA
Use normal .py modules for reusable/production application code.
Important: Notebook cells share state. Running cells out of order can create confusing results. Restart + Run All is a useful sanity check.