Vectorization Flashcards

1
Q

Q: What is vectorization in the context of programming?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Q: Which Python library is mentioned for vectorization?

A

A: NumPy, which is the most widely used numerical linear algebra library in Python and machine learning.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Q: How does indexing work in Python for arrays?

A

A: Indexing starts from 0, so the first element is accessed with index 0, the second with index 1, etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Q: What is a fundamental benefit of vectorization?

A

A: It allows code to be written in a concise manner and boosts performance by leveraging parallel computation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Q: How do you compute the dot product without vectorization in a loop?

A

A: Use a loop to sum the products of each pair of elements from the vectors w and x, then add b.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Q: How do you compute the dot product using vectorization in Python?

A

A: Use np.dot(w, x) to compute the dot product, then add b.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Q: What makes the vectorized implementation using NumPy faster?

A

A: It uses parallel hardware capabilities, making it more efficient than sequential loop calculations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Q: Why is vectorization more efficient for large values of n?

A

A: Because it reduces typing and computation time by handling operations on entire arrays simultaneously.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Q: What does the function np.dot() accomplish?

A

A: It calculates the dot product of two vectors, optimizing the operation through vectorization.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Q: Can vectorization make use of a GPU?

A

A: Yes, it takes advantage of GPU acceleration which is often used to speed up machine learning computations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Q: How are variables accessed in a loop for non-vectorized implementations?

A

A: By iterating over indices and accessing each element separately, such as w[j] * x[j].

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Q: Overall, why does vectorization enhance the execution speed of a program?

A

A: Because it minimizes the number of operations by directly applying mathematical operations at an array or vector level, enabling concurrent computation streams.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Q: How does a for-loop operation proceed in a non-vectorized implementation?

A

A: It processes operations sequentially, one step at a time for each index in the loop.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Q: How does vectorization improve operations in computing?

A

A: It processes operations in parallel, performing multiple calculations simultaneously.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Q: Why is vectorization particularly important for large data sets?

A

A: It scales efficiently and performs computations faster, which is critical for training large models.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Q: How can a parameter update step be written using vectorization?

A

A: W=W−learning rate×D.

17
Q

Q: What does vectorization rely on to perform its operations?

A

A: Parallel processing hardware like GPUs and optimized numerical libraries like NumPy.

18
Q

Q: What advantage does NumPy offer for vectorized operations?

A

A: It allows the use of optimized functions like np.dot() for efficient calculations.

19
Q

Q: How are NumPy arrays related to vectorization?

A

A: They enable easy representation and manipulation of vectors for quick mathematical operations.

20
Q

Q: In the context of vectorization, why is NumPy’s dot function faster than a loop?

A

A: It leverages parallel processing to perform the dot product efficiently.

21
Q

Q: What is an important benefit of using vectorized code beyond speed?

A

A: It often reduces the amount of code needed, making it more readable and maintainable.

22
Q

Q: Why might the speed difference of vectorization not be as noticeable with only 16 features?

A

A: The computational overhead is more apparent with thousands of features and large datasets.

23
Q

Q: What importantly enables NumPy’s efficiency in executing vectorized operations?

A

A: Its ability to utilize hardware acceleration, applying multiple processors in parallel.