Recall & Review
beginner
Why might NumPy sometimes be too slow for certain tasks?
NumPy can be slow when operations require complex loops or when Python-level loops are used instead of vectorized operations. It also struggles with tasks that need parallel processing or just-in-time compilation.
Click to reveal answer
beginner
What is Numba and how does it help when NumPy is not fast enough?
Numba is a tool that compiles Python functions to fast machine code at runtime. It speeds up loops and numerical code by using just-in-time (JIT) compilation, making Python code run closer to C speed.
Click to reveal answer
intermediate
How does using Cython improve performance beyond NumPy?
Cython lets you write Python code with optional type declarations that get compiled into C code. This reduces Python overhead and speeds up loops and calculations, especially when NumPy vectorization is not enough.
Click to reveal answer
intermediate
What role does parallel processing play when NumPy is not fast enough?
Parallel processing splits work across multiple CPU cores or machines. NumPy alone is mostly single-threaded, so using parallel tools like multiprocessing or libraries like Dask can speed up large or complex computations.
Click to reveal answer
beginner
When should you consider switching from NumPy to other tools for speed?
If your code has many Python loops, complex logic, or needs to run on multiple cores, and vectorized NumPy is not enough, consider tools like Numba, Cython, or parallel libraries to get better speed.
Click to reveal answer
Which of these is a common reason NumPy might be slow?
✗ Incorrect
Python loops are slower than NumPy's vectorized operations because they run at Python speed, not optimized machine code.
What does Numba do to speed up Python code?
✗ Incorrect
Numba uses just-in-time compilation to turn Python functions into fast machine code.
Which tool allows adding type declarations to Python code for speed?
✗ Incorrect
Cython lets you add types and compiles Python code to C for better performance.
Why might parallel processing help when NumPy is not fast enough?
✗ Incorrect
Parallel processing splits tasks across cores to speed up computation.
When should you consider using tools like Numba or Cython?
✗ Incorrect
Numba and Cython help speed up code that can't be fully optimized by NumPy vectorization.
Explain why NumPy might not be fast enough for some numerical tasks and name two tools that can help improve performance.
Think about how Python loops compare to vectorized operations and what tools compile Python code.
You got /4 concepts.
Describe how parallel processing can enhance performance when using NumPy and give an example of a library that supports it.
Consider how dividing work helps and which Python tools can do this.
You got /4 concepts.