SOL-C01 · Question #1
You have a Python script running in a Snowflake Notebook that retrieves data from a Snowflake table, performs some complex calculations, and then visualizes the results using Matplotlib. The script is
The correct answer is B. Vectorize the calculations using NumPy instead of looping through the data row by row.. Why B is correct: Since the SQL query is already optimized, the bottleneck lies in the Python computation layer. NumPy vectorization replaces slow Python loops with highly optimized C-level operations on entire arrays at once, which can yield 10–100x speedups for numerical worklo
Question
You have a Python script running in a Snowflake Notebook that retrieves data from a Snowflake table, performs some complex calculations, and then visualizes the results using Matplotlib. The script is running slowly, even after optimizing the SQL query. Which of the following steps would MOST likely improve the performance of the Python script within the Snowflake Notebook environment?
Options
- AIncrease the size of the virtual warehouse associated with the Snowflake session.
- BVectorize the calculations using NumPy instead of looping through the data row by row.
- CUse the '%%osql' magic command to execute the calculations directly in Snowflake SQL.
- DStore the intermediate results in a Snowflake temporary table and retrieve them later.
- EUse a smaller data sample by adding 'LIMIT 1 00' in the SQL query to speed up the process.
How the community answered
(25 responses)- A4% (1)
- B64% (16)
- C8% (2)
- D20% (5)
- E4% (1)
Explanation
Why B is correct: Since the SQL query is already optimized, the bottleneck lies in the Python computation layer. NumPy vectorization replaces slow Python loops with highly optimized C-level operations on entire arrays at once, which can yield 10–100x speedups for numerical workloads - exactly the "complex calculations" described.
Why the distractors are wrong:
- A - Warehouse size affects SQL execution speed, not Python runtime; the problem states SQL is already optimized, so more compute nodes won't help Python loops.
- C -
%%sql(not%%osql) pushes logic into Snowflake SQL, which could help in some cases, but "complex calculations" may not be expressible in SQL, and the question asks what most likely improves the Python script itself. - D - Storing intermediate results in a temp table adds I/O overhead and doesn't speed up the calculation step at all.
- E - Sampling with
LIMIT 100changes the result, not the performance of the actual computation - it sacrifices correctness for the appearance of speed.
Memory tip: Think of it as "fix the right layer" - SQL slow → tune the warehouse or query; Python slow → vectorize with NumPy. The constraint "SQL already optimized" is the key signal that shifts the fix into the Python computation layer.
Topics
Community Discussion
No community discussion yet for this question.