Practice
n x n to a smaller size m x m using NumPy slicing?Solution
Step 1: Understand NumPy slicing
NumPy slicing creates a view, not a copy, so it operates in constant time.Step 2: Evaluate the complexity
The operation does not depend on the size of the arrays but on the slicing indices.Final Answer:
Option B -> Option BQuick Check:
NumPy slicing is O(1) due to views. [OK]
Solution
Step 1: Consider class imbalance
Stratified K-Fold ensures each fold has the same class distribution as the entire dataset.Step 2: Eliminate wrong options
Standard K-Fold and D do not preserve class distribution. Leave-One-Out is inefficient for large datasets.Final Answer:
Option A -> Option AQuick Check:
Use Stratified K-Fold for class balance. [OK]
Solution
Step 1: Understand text preprocessing needs
In text classification, irrelevant words can add noise.Step 2: Evaluate preprocessing steps
Removing stop words (Removing stop words) reduces noise and improves performance. Options A and C are less relevant as MultinomialNB doesn't require normalized or scaled features. Applying PCA for dimensionality reduction is unnecessary as PCA isn't typically used for text data.Final Answer:
Option C -> Option CQuick Check:
Remove stop words to reduce noise in text data. [OK]
Solution
Step 1: Identify computational bottlenecks
Looping over pairs is inefficient for large datasets.Step 2: Optimize using matrix operations
Precomputing norms and using matrix multiplication reduces redundant calculations.Final Answer:
Option C -> Option CQuick Check:
Matrix ops reduce redundancy. [OK]
def augment_image(img):
img = np.flip(img, axis=1)
img = img[10:110, 10:110]
img = (img - np.mean(img)) / np.std(img)
return imgSolution
Step 1: Identify memory inefficiencies
Intermediate assignments create unnecessary copies.Step 2: Evaluate optimization strategies
Chaining operations reduces memory usage by avoiding intermediate arrays.Final Answer:
Option A -> Option AQuick Check:
Chain operations to reduce memory usage. [OK]
