Recall & Review
beginner
What is a key difference between a NumPy array and a Python list in terms of performance?
NumPy arrays are faster for numerical operations because they store data in a continuous block of memory and use optimized C code, while Python lists store references to objects and have more overhead.
Click to reveal answer
beginner
Why are NumPy arrays more memory efficient than Python lists?
NumPy arrays store elements of the same data type in a compact, fixed-size block of memory, unlike Python lists which store pointers to objects, causing extra memory use.
Click to reveal answer
intermediate
How does vectorization in NumPy improve performance compared to Python lists?
Vectorization allows NumPy to perform operations on whole arrays at once using optimized low-level code, avoiding slow Python loops over list elements.
Click to reveal answer
beginner
Which data structure is better for mixed data types: NumPy array or Python list?
Python lists are better for mixed data types because NumPy arrays require all elements to be of the same type for performance benefits.
Click to reveal answer
intermediate
What happens if you try to store different data types in a NumPy array?
NumPy will upcast all elements to a common data type that can hold all values, often converting numbers to floats or strings, which can reduce performance.
Click to reveal answer
Why are NumPy arrays generally faster than Python lists for numerical operations?
✗ Incorrect
NumPy arrays store data in continuous memory blocks and use optimized C code, making numerical operations faster.
Which data structure uses more memory for the same number of numerical elements?
✗ Incorrect
Python lists store pointers to objects, which uses more memory than NumPy arrays that store raw data compactly.
What is vectorization in NumPy?
✗ Incorrect
Vectorization means applying operations to entire arrays at once, which is faster than looping over elements.
If you need to store numbers and strings together, which is better?
✗ Incorrect
Python lists can store mixed data types easily, while NumPy arrays require a single data type.
What happens to performance if a NumPy array contains mixed data types?
✗ Incorrect
NumPy upcasts to a common type, often strings, which slows down operations.
Explain why NumPy arrays are faster and more memory efficient than Python lists for numerical data.
Think about how data is stored and processed under the hood.
You got /4 concepts.
Describe a situation where using a Python list is better than a NumPy array.
Consider data types and use cases.
You got /3 concepts.