This question has a lot of layers and I underestimated it at first.
Start by clarifying the requirements and edge cases, then outline a vectorized NumPy solution that uses a fixed seed, handles all-zero columns by setting them to uniform or zero, and verifies column sums with np.allclose. Finally, analyze time and space complexity and provide a unit test using pytest or unittest.
Pro tip: Mention that using a fixed seed ensures reproducibility, but also discuss the trade-off between reproducibility and randomness in production; for all-zero columns, explicitly state your handling strategy (e.g., uniform distribution) and justify it.
Confirm the parameters (n=10, p=0.3, shape 100x100), the meaning of normalization (sum to 1 per column), and how to handle all-zero columns (e.g., set to uniform or leave as zeros).
Use np.random.seed for reproducibility, generate the matrix with np.random.binomial, compute column sums, and normalize by dividing each column by its sum, handling zero sums explicitly.
Check that all column sums are approximately 1 using np.allclose with a tolerance, and ensure no division by zero occurs.
State that time complexity is O(m*n) for generating and normalizing (m=100, n=100), and space complexity is O(m*n) for storing the matrix.
Create a test that checks the shape, column sums, and reproducibility with the same seed, and verifies that all-zero columns are handled as specified.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.