2. Array Indexing, Slicing & Matrix Operations for Formulation
In pharmaceutical formulation development, dissolution profiles and stability testing generate 2D matrices (rows = time points, columns = sample batches). NumPy provides zero-indexed indexing and slicing (`[start:stop:step]`) to extract specific time points, replicate runs, or calculate column-wise means and standard deviations.
Analyzing drug release percentages across 3 distinct production batches at 5, 15, 30, 45, and 60 minutes.
import numpy as np
# Rows = Time points (5, 15, 30, 45, 60 min), Columns = Batches (Batch A, Batch B, Batch C)
dissolution_matrix = np.array([
[28.4, 26.9, 29.1], # 5 min
[54.2, 52.8, 55.0], # 15 min
[78.9, 77.4, 80.2], # 30 min
[91.5, 89.8, 92.4], # 45 min
[98.7, 97.2, 99.1] # 60 min
])
# Mean dissolution across all batches at each time point (axis=1 calculates row-wise)
mean_profile = np.mean(dissolution_matrix, axis=1)
std_profile = np.std(dissolution_matrix, axis=1)
time_points = [5, 15, 30, 45, 60]
for t, mean, std in zip(time_points, mean_profile, std_profile):
print(f"Time {t:2d} min: Mean = {mean:.2f}% | SD = ±{std:.2f}%")- `axis=0` performs operations down columns (per batch/variable).
- `axis=1` performs operations across rows (per time point/sample).
- Matrix multiplication `np.dot(A, B)` or `@` operator is used in linear pharmacokinetic compartment modeling.
2D मैट्रिक्स में पंक्तियां (Rows) समय बिंदु और कॉलम (Columns) अलग-अलग बैच होते हैं। axis=1 से हर समय बिंदु पर औसत डिसोल्यूशन निकाला जाता है।