Goto

Collaborating Authors

 vectorization and broadcasting


Vectorization: Must-know Technique to Speed Up Operations 100x Faster

#artificialintelligence

In current data science or machine learning applications, huge datasets and sophisticated networks are usually involved. Thus, code efficiency becomes really important when it comes to handling the computational workload. As an example, in a classic Multi-layer Perceptron (aka Feedforward Neural Network), the network typically contains multiple linear layers. Let's say the input layer contains 64 neurons while the first hidden layer contains 128 hidden neurons. Then, in order to calculate the output of the hidden layer given an input, the straightforward way would be to use the np.dot method provided by the Numpy library: As we can see, this method takes 1.4 microseconds on average.


#006B Vectorization and Broadcasting in Python Master Data Science

#artificialintelligence

A vectorization is basically the art of getting rid of explicit for loops whenever possible. With the help of vectorization, operations are applied to whole arrays instead of individual elements. The rule of thumb to remember is to avoid using explicit loops in your code. Deep learning algorithms tend to shine when trained on large datasets, so it's important that your code runs quickly. Otherwise, your code might take a long time to get your result.