Learn Before
Example

Example: Computational Speedup of Vectorized Addition

The computational advantage of vectorization can be demonstrated by comparing the time taken to add two high-dimensional vectors. For instance, when adding two 10,00010,000-dimensional vectors of all ones, using an explicit element-by-element for-loop in Python is significantly slower than using the vectorized elementwise addition operator (e.g., ++). The vectorized operation leverages optimized linear algebra libraries to perform the entire addition simultaneously, yielding an order-of-magnitude speedup and dramatically faster execution times compared to the loop-based method.

0

1

Updated 2026-05-02

Contributors are:

Who are from:

Tags

D2L

Dive into Deep Learning @ D2L