top of page

Vectorization in machine learning

  • neovijayk
  • Jun 13, 2020
  • 1 min read

In this article we will try to understand this term Vectorization and also why its important in Machnine Learning or Deep Learning to use it.

What is Vectorization?

  1. We know in Python loops such as for loop takes lot of time if used in computation. They are time consuming operations

  2. Vectorization is basically the art of getting rid of explicit for loops in your code.

  3. The non-vectorize version of code took something like 300 times longer than the vectorize version of code in the execution. That means if Vectorized version of code is used then it actually runs over 300 times faster. (source: Andrew Ng. Course 1 of deeplearning.ai Specialization)

Why Vectorization is important?

  1. A lot of scaleable deep learning implementations are done on a GPU or a graphics processing unit

  2. both GPU and CPU have parallelization instructions.

  3. They’re sometimes called SIMD instructions. This stands for a single instruction multiple data.

  4. But what this basically means is that, if you use built-in functions such as this np.function or other functions that don’t require you explicitly implementing a for loop.

Example of Vectorization using Numpy:

The vectorize version in the above picture of lines of code took 1.5 milliseconds.  The explicit for loop and non-vectorize version took about 400, almost 500 milliseconds.

Comments


Subscribe to BrainStorm newsletter

For notifications on latest posts/blogs

Thanks for submitting!

  • Twitter
  • Facebook
  • Linkedin

© 2023 by my-learnings.   Copy rights Vijay@my-learnings.com

bottom of page