Skip to content

Commit 7652cc4

Browse files
committed
Basic Link To orphan pages align.. experimental Notes
1 parent 293bb2e commit 7652cc4

9 files changed

Lines changed: 608 additions & 22 deletions

File tree

pages/Data Science.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ displayTitle: Data Science
144144
- # Python for Data Science
145145
collapsed:: true
146146
- See [[Python]] for full language reference. This section covers the data science-specific stack.
147-
- ## NumPy — Numerical Computing
147+
- ## [[NumPy]] — Numerical Computing
148148
collapsed:: true
149149
- ```python
150150
import numpy as np
@@ -185,7 +185,7 @@ displayTitle: Data Science
185185
print(m.max()) # 9
186186
print(m.argmax()) # 8 (flat index)
187187
```
188-
- ## Pandas — Data Manipulation
188+
- ## [[Pandas]] — Data Manipulation
189189
collapsed:: true
190190
- ```python
191191
import pandas as pd
@@ -245,7 +245,7 @@ displayTitle: Data Science
245245
```
246246
- # Data Visualization
247247
collapsed:: true
248-
- ## Matplotlib — Core Plotting
248+
- ## [[Matplotlib]] — Core Plotting
249249
collapsed:: true
250250
- ```python
251251
import matplotlib.pyplot as plt
@@ -279,7 +279,7 @@ displayTitle: Data Science
279279
plt.bar(categories, values, color="coral")
280280
plt.show()
281281
```
282-
- ## Seaborn — Statistical Visualization
282+
- ## [[Seaborn]] — Statistical Visualization
283283
collapsed:: true
284284
- ```python
285285
import seaborn as sns
@@ -309,7 +309,7 @@ displayTitle: Data Science
309309
sns.pairplot(tips, hue="sex")
310310
plt.show()
311311
```
312-
- ## Plotly — Interactive Visualization
312+
- ## [[Plotly]] — Interactive Visualization
313313
collapsed:: true
314314
- ```python
315315
import plotly.express as px

pages/Matplotlib.md

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,78 @@
11
---
2-
seoTitle: Matplotlib Python Library Data Visualization Reference Guide
2+
seoTitle: Matplotlib Python Library - Data Visualization Reference Guide
33
description: "Matplotlib creates static, animated, and interactive visualizations in Python. Covers pyplot, axes, subplots, plot types, customization, and saving figures."
44
keywords: "Matplotlib, Python visualization, pyplot, subplots, plot types, data visualization, charts, graphs, figure customization, Python library, scientific plotting"
55
---
66

7-
- [Docs](https://matplotlib.org/stable/contents.html)
7+
- # 📘 **Overview**
8+
- **What is it?**: Matplotlib is a comprehensive library for creating static, animated, and interactive visualizations in Python. It is the core graphics engine behind many other plotting libraries (such as Seaborn and Pandas plotting).
9+
- **Key Features**:
10+
- **Highly Customizable**: Total control over fonts, axes, line styles, colors, and layout configurations.
11+
- **Two Interfaces**: State-based interface (via `pyplot` - good for quick plots) and Object-Oriented interface (recommended for clean, robust layouts).
12+
- **Export Options**: Export figures to multiple high-quality formats (PNG, PDF, SVG, etc.).
13+
- **Installation**:
14+
- ```bash
15+
pip install matplotlib
16+
```
17+
- # 🧾 **Core Concepts**
18+
- **Figure**: The overall window or page that contains all plot elements (axes, title, legend, etc.). Think of it as a canvas.
19+
- **Axes**: A coordinate area within a Figure where data is plotted. A single Figure can contain multiple Axes (subplots).
20+
- **Axis**: The actual helper lines and ticks marking scale values (e.g. X-axis, Y-axis).
21+
- # 💻 **Common Code Patterns & Cheat Sheet**
22+
- **Basic Line Plot (Object-Oriented Style)**:
23+
- ```python
24+
import matplotlib.pyplot as plt
25+
import numpy as np
26+
27+
# Generate data
28+
x = np.linspace(0, 10, 100)
29+
y = np.sin(x)
30+
31+
# Create Figure and Axes
32+
fig, ax = plt.subplots(figsize=(8, 4))
33+
34+
# Plot data
35+
ax.plot(x, y, label="Sine Wave", color="purple", linewidth=2, linestyle="-")
36+
37+
# Customize labels & grid
38+
ax.set_title("Simple Sine Plot", fontsize=14)
39+
ax.set_xlabel("X-Axis")
40+
ax.set_ylabel("Y-Axis")
41+
ax.legend(loc="upper right")
42+
ax.grid(True, linestyle="--", alpha=0.6)
43+
44+
# Render / Show
45+
plt.tight_layout()
46+
plt.show()
47+
```
48+
- **Creating Subplots (Multi-plot Layouts)**:
49+
- ```python
50+
# Create 1 row with 2 columns of plots
51+
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 5))
52+
53+
# Left plot: Scatter
54+
ax1.scatter(np.random.rand(50), np.random.rand(50), color="blue", alpha=0.5)
55+
ax1.set_title("Scatter Plot")
56+
57+
# Right plot: Histogram
58+
ax2.hist(np.random.randn(1000), bins=30, color="orange", edgecolor="black")
59+
ax2.set_title("Histogram")
60+
61+
plt.tight_layout()
62+
plt.show()
63+
```
64+
- **Saving Plots**:
65+
- ```python
66+
fig, ax = plt.subplots()
67+
ax.plot([1, 2, 3], [4, 5, 6])
68+
69+
# Save as PNG with transparent background and high resolution
70+
fig.savefig("my_plot.png", dpi=300, bbox_inches="tight", transparent=True)
71+
```
72+
- # 💡 **Best Practices & Tips**
73+
- **Object-Oriented API**: Always prefer using `fig, ax = plt.subplots()` rather than calling `plt.plot()` directly. The OO API keeps your code cleaner when working with subplots or complex layouts.
74+
- **Tight Layout**: Always call `plt.tight_layout()` before saving or showing a plot to prevent axes labels and titles from overlapping.
75+
- **Closing Figures**: If you are generating many plots in a loop (e.g., in a background job or web server), always call `plt.close(fig)` or `plt.close('all')` to prevent memory leaks.
76+
- # 🔗 **Navigation & Internal Links**
77+
- **Parent**: [[Python]]
78+
- **Related Notes**: [[Data Science]] | [[Machine Learning]] | [[NumPy]] | [[Pandas]] | [[Seaborn]] | [[Plotly]]

pages/NumPy.md

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,65 @@
11
---
2-
seoTitle: NumPy Python Library Array Operations and Scientific Computing
2+
seoTitle: NumPy Python Library - Array Operations and Scientific Computing
33
description: "NumPy is the foundation of scientific Python. Covers ndarray, broadcasting, indexing, linear algebra, random number generation, and performance optimization."
44
keywords: "NumPy, Python arrays, ndarray, broadcasting, linear algebra, scientific computing, random numbers, indexing, slicing, Python library, numerical computing"
55
---
66

7-
- [docs](https://numpy.org/doc/)
7+
- # 📘 **Overview**
8+
- **What is it?**: NumPy (Numerical Python) is the foundational package for scientific computing in Python. It provides support for large, multi-dimensional arrays and matrices, along with a collection of high-level mathematical functions to operate on these arrays.
9+
- **Key Features**:
10+
- **ndarray**: A fast and space-efficient multidimensional array providing vectorized arithmetic operations.
11+
- **Broadcasting**: A powerful mechanism that allows operations on arrays of different shapes.
12+
- **Vectorization**: Elimination of explicit Python loops in numerical operations, leading to C-level execution speeds.
13+
- **Installation**:
14+
- ```bash
15+
pip install numpy
16+
```
17+
- # 🧾 **Core Concepts**
18+
- **ndarray**: An N-dimensional array object where all elements must be of the same data type (`dtype`).
19+
- **Vectorization**: Running element-wise calculations directly in C, which avoids the overhead of standard Python loops.
20+
- **Broadcasting**: Rules specifying how operations work on arrays of different shapes (e.g., adding a scalar to an array, or multiplying a 2D array by a 1D array).
21+
- **Slicing and Views**: Sub-arrays created by slicing are "views" of the original data. Modifying a view modifies the original array (no copy is made unless explicitly requested with `.copy()`).
22+
- # 💻 **Common Code Patterns & Cheat Sheet**
23+
- **Array Creation & Properties**:
24+
- ```python
25+
import numpy as np
26+
27+
# Creation from list
28+
arr = np.array([1, 2, 3, 4])
29+
30+
# Help helper functions
31+
zeros = np.zeros((2, 3)) # 2x3 matrix of zeros
32+
ones = np.ones((3, 3), dtype=int) # 3x3 matrix of ones
33+
steps = np.arange(0, 10, 2) # [0 2 4 6 8]
34+
linspace = np.linspace(0, 1, 5) # [0. 0.25 0.5 0.75 1.]
35+
identity = np.eye(3) # 3x3 Identity matrix
36+
```
37+
- **Indexing, Slicing & Boolean Masking**:
38+
- ```python
39+
grid = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
40+
41+
# Slice: first two rows, last two columns
42+
sub_grid = grid[:2, 1:]
43+
44+
# Boolean Masking (extremely fast filtering)
45+
mask = grid > 5
46+
filtered_vals = grid[mask] # [6 7 8 9]
47+
```
48+
- **Vectorized Operations & Broadcasting**:
49+
- ```python
50+
a = np.array([1, 2, 3])
51+
b = np.array([[10], [20], [30]])
52+
53+
# Broadcasting: adds (3,) to (3,1) resulting in a (3,3) matrix
54+
result = a + b
55+
# [[11 12 13],
56+
# [21 22 23],
57+
# [31 32 33]]
58+
```
59+
- # 💡 **Best Practices & Tips**
60+
- **Avoid Explicit Loops**: Never loop over NumPy arrays using Python `for` loops if a vectorized alternative exists.
61+
- **View vs Copy**: Be careful when slicing: `slice = arr[1:3]` does not copy memory. Use `slice = arr[1:3].copy()` if you want a new independent array.
62+
- **Dtype Management**: Choose specific dtypes (like `np.int8`, `np.float32`) to save memory when working with large datasets.
63+
- # 🔗 **Navigation & Internal Links**
64+
- **Parent**: [[Python]]
65+
- **Related Notes**: [[Data Science]] | [[Machine Learning]] | [[Pandas]] | [[Matplotlib]] | [[SciPy]]

pages/Pandas.md

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,69 @@
11
---
2-
seoTitle: Pandas Python Library DataFrame Operations Reference Guide
2+
seoTitle: Pandas Python Library - DataFrame Operations Reference Guide
33
description: "Pandas provides powerful data manipulation with DataFrames. Covers indexing, groupby, merge, pivot tables, time series, missing data handling, and I/O."
44
keywords: "Pandas, Python DataFrame, groupby, merge, pivot table, time series, missing data, indexing, data manipulation, Python library, data analysis, CSV reading"
55
---
66

7-
- [Docs]( https://pandas.pydata.org/pandas-docs/stable/)
7+
- # 📘 **Overview**
8+
- **What is it?**: Pandas is a fast, powerful, flexible, and easy-to-use open-source data analysis and manipulation tool built on top of the Python programming language.
9+
- **Key Features**:
10+
- **DataFrame**: A two-dimensional tabular data structure with labeled axes (rows and columns).
11+
- **Series**: A one-dimensional labeled array capable of holding any data type.
12+
- **Alignment**: Auto-alignment of data in operations based on row/column indices.
13+
- **File Support**: Out-of-the-box reading and writing support for CSV, Excel, SQL databases, JSON, Parquet, and more.
14+
- **Installation**:
15+
- ```bash
16+
pip install pandas
17+
```
18+
- # 🧾 **Core Concepts**
19+
- **Series**: The basic 1D building block of Pandas.
20+
- **DataFrame**: The 2D table representing data, composed of multiple Series (columns) sharing the same Index.
21+
- **Indexing (`loc` vs `iloc`)**:
22+
- `loc`: Label-based selection (e.g. `df.loc[0, 'column_name']`).
23+
- `iloc`: Integer/Position-based selection (e.g. `df.iloc[0, 1]`).
24+
- **Missing Data**: Pandas uses `NaN` (Not a Number) to represent missing values and provides native functions like `isnull()`, `dropna()`, and `fillna()`.
25+
- # 💻 **Common Code Patterns & Cheat Sheet**
26+
- **DataFrame Creation & Loading**:
27+
- ```python
28+
import pandas as pd
29+
30+
# Load from CSV
31+
df = pd.read_csv("data.csv")
32+
33+
# Create from dictionary
34+
data = {"Name": ["Alice", "Bob"], "Age": [25, 30]}
35+
df = pd.DataFrame(data)
36+
```
37+
- **Selection & Filtering**:
38+
- ```python
39+
# Select single column
40+
ages = df["Age"]
41+
42+
# Filter rows based on conditions
43+
adults = df[df["Age"] >= 18]
44+
45+
# Select specific rows and columns using loc
46+
subset = df.loc[df["Age"] > 20, ["Name"]]
47+
```
48+
- **Grouping & Aggregation**:
49+
- ```python
50+
# Calculate mean age by city
51+
grouped = df.groupby("City")["Age"].mean()
52+
53+
# Perform multiple aggregations
54+
summary = df.groupby("City").agg({"Age": ["mean", "min", "max"]})
55+
```
56+
- **Data Merging & Joining**:
57+
- ```python
58+
# Merge two DataFrames on a common column
59+
df1 = pd.DataFrame({"ID": [1, 2], "Val": ["A", "B"]})
60+
df2 = pd.DataFrame({"ID": [2, 3], "Score": [88, 95]})
61+
merged = pd.merge(df1, df2, on="ID", how="inner")
62+
```
63+
- # 💡 **Best Practices & Tips**
64+
- **Avoid `.iterrows()`**: Never iterate over rows using `.iterrows()` for numerical calculations. Instead, use vectorized operations or `.apply()` (and prefer `.apply()` only when vectorization is not possible).
65+
- **SettingWithCopyWarning**: When modifying a slice, always make an explicit copy: `df_slice = df[df['Age'] > 20].copy()`.
66+
- **Categorical Columns**: Convert text columns with low cardinality to `category` dtype using `df['Col'] = df['Col'].astype('category')` to save substantial memory.
67+
- # 🔗 **Navigation & Internal Links**
68+
- **Parent**: [[Python]]
69+
- **Related Notes**: [[Data Science]] | [[Machine Learning]] | [[NumPy]] | [[Matplotlib]]

pages/PyTorch.md

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,87 @@
11
---
2-
seoTitle: PyTorch Python Library Deep Learning Framework Reference Guide
2+
seoTitle: PyTorch Python Library - Deep Learning Framework Reference Guide
33
description: "PyTorch is a dynamic deep learning framework. Covers tensors, autograd, neural networks, optimizers, DataLoader, GPU acceleration, and model training patterns."
44
keywords: "PyTorch, deep learning, tensors, autograd, neural networks, optimizers, DataLoader, GPU, CUDA, model training, Python library, machine learning"
55
---
66

7-
- [Docs](https://pytorch.org/docs/stable/)
7+
- # 📘 **Overview**
8+
- **What is it?**: PyTorch is an open-source machine learning library developed by Meta's AI Research lab. It is widely used for applications such as computer vision and natural language processing, due to its dynamic computation graph and Pythonic nature.
9+
- **Key Features**:
10+
- **Dynamic Computation Graphs**: Computations are defined dynamically at runtime (Imperative / Eager mode), allowing easy debugging and dynamic model architectures.
11+
- **Tensor Computation**: Support for multi-dimensional arrays (Tensors) with strong GPU acceleration via CUDA.
12+
- **Autograd Module**: Automatic differentiation engine that powers backpropagation.
13+
- **Installation**:
14+
- ```bash
15+
# Core CPU/GPU installation (verify CUDA version on pytorch.org)
16+
pip install torch torchvision torchaudio
17+
```
18+
- # 🧾 **Core Concepts**
19+
- **Tensors**: The core data structure in PyTorch, similar to NumPy's `ndarray` but capable of running on a GPU.
20+
- **Autograd**: The automatic differentiation engine. By setting `requires_grad=True` on a tensor, PyTorch tracks operations on it and automatically computes gradients during the backward pass.
21+
- **nn.Module**: The base class for all neural network modules. Models inherit from this class and implement the `forward` pass.
22+
- **Dataset & DataLoader**: Classes to manage data parsing and batching during training.
23+
- # 💻 **Common Code Patterns & Cheat Sheet**
24+
- **Tensor Operations & GPU Usage**:
25+
- ```python
26+
import torch
27+
28+
# Create tensor from list
29+
x = torch.tensor([[1.0, 2.0], [3.0, 4.0]], requires_grad=True)
30+
31+
# Move to GPU if available
32+
device = "cuda" if torch.cuda.is_available() else "cpu"
33+
x = x.to(device)
34+
35+
# Basic math
36+
y = x ** 2 + 2
37+
z = y.mean()
38+
39+
# Backpropagation
40+
z.backward()
41+
print(x.grad) # prints gradients of z w.r.t x
42+
```
43+
- **Defining a Neural Network**:
44+
- ```python
45+
import torch.nn as nn
46+
47+
class SimpleClassifier(nn.Module):
48+
def __init__(self, input_dim, hidden_dim, output_dim):
49+
super().__init__()
50+
self.linear1 = nn.Linear(input_dim, hidden_dim)
51+
self.relu = nn.ReLU()
52+
self.linear2 = nn.Linear(hidden_dim, output_dim)
53+
54+
def forward(self, x):
55+
out = self.linear1(x)
56+
out = self.relu(out)
57+
out = self.linear2(out)
58+
return out
59+
```
60+
- **Training Loop Pattern**:
61+
- ```python
62+
import torch.optim as optim
63+
64+
# Instantiate model, optimizer, and loss function
65+
model = SimpleClassifier(input_dim=10, hidden_dim=20, output_dim=2).to(device)
66+
optimizer = optim.Adam(model.parameters(), lr=0.001)
67+
criterion = nn.CrossEntropyLoss()
68+
69+
# Dummy input & target
70+
inputs = torch.randn(32, 10).to(device)
71+
targets = torch.randint(0, 2, (32,)).to(device)
72+
73+
# Single step of training
74+
model.train() # set to training mode
75+
optimizer.zero_grad() # clear previous gradients
76+
outputs = model(inputs) # forward pass
77+
loss = criterion(outputs, targets)
78+
loss.backward() # backward pass (compute gradients)
79+
optimizer.step() # update weights
80+
```
81+
- # 💡 **Best Practices & Tips**
82+
- **Inference Mode**: Always wrap validation/inference code blocks in `with torch.no_grad():` to save memory and compute.
83+
- **Mode Toggling**: Toggle `model.train()` and `model.eval()` to correctly configure modules like Dropout and BatchNorm.
84+
- **Gradient Zeroing**: Never forget to run `optimizer.zero_grad()` before computing gradients, otherwise gradients will accumulate.
85+
- # 🔗 **Navigation & Internal Links**
86+
- **Parent**: [[Python]]
87+
- **Related Notes**: [[Machine Learning]] | [[Data Science]] | [[NumPy]] | [[Pandas]]

0 commit comments

Comments
 (0)