Vectorization Flashcards
Q: What is vectorization in the context of programming?
A: It’s a technique that makes code shorter and runs it more efficiently by utilizing modern numerical linear algebra libraries and hardware like GPUs.
Q: Which Python library is mentioned for vectorization?
A: NumPy, which is the most widely used numerical linear algebra library in Python and machine learning.
Q: How does indexing work in Python for arrays?
A: Indexing starts from 0, so the first element is accessed with index 0, the second with index 1, etc.
Q: What is a fundamental benefit of vectorization?
A: It allows code to be written in a concise manner and boosts performance by leveraging parallel computation.
Q: How do you compute the dot product without vectorization in a loop?
A: Use a loop to sum the products of each pair of elements from the vectors w and x, then add b.
Q: How do you compute the dot product using vectorization in Python?
A: Use np.dot(w, x) to compute the dot product, then add b.
Q: What makes the vectorized implementation using NumPy faster?
A: It uses parallel hardware capabilities, making it more efficient than sequential loop calculations.
Q: Why is vectorization more efficient for large values of n?
A: Because it reduces typing and computation time by handling operations on entire arrays simultaneously.
Q: What does the function np.dot() accomplish?
A: It calculates the dot product of two vectors, optimizing the operation through vectorization.
Q: Can vectorization make use of a GPU?
A: Yes, it takes advantage of GPU acceleration which is often used to speed up machine learning computations.
Q: How are variables accessed in a loop for non-vectorized implementations?
A: By iterating over indices and accessing each element separately, such as w[j] * x[j].
Q: Overall, why does vectorization enhance the execution speed of a program?
A: Because it minimizes the number of operations by directly applying mathematical operations at an array or vector level, enabling concurrent computation streams.
Q: How does a for-loop operation proceed in a non-vectorized implementation?
A: It processes operations sequentially, one step at a time for each index in the loop.
Q: How does vectorization improve operations in computing?
A: It processes operations in parallel, performing multiple calculations simultaneously.
Q: Why is vectorization particularly important for large data sets?
A: It scales efficiently and performs computations faster, which is critical for training large models.