Awesome NumPy tricks every data scientist should know

Manpreet Singh
3 min readSep 23, 2021

Welcome back! NumPy is a must-have package for data science, it’s used in almost any data science related project, so let’s talk about some awesome NumPy tricks that every data scientist should know!

Comparing 2 arrays

First up, we can actually compare 2 different arrays, essentially comparing the likeness between 2 arrays. To do this, we use the “==” command:

import numpy as npa = np.zeros((2,10))b = np.zeros((1,10))#COMPARING THE 2 ARRAYS
a == b

The output will be a bunch of true/false statements:

In this case, it’s all true, but you can compare any array like this.

Creating a Placeholder Array

Another awesome trick we have within NumPy is the ability of creating a placeholder array, what is a placeholder array? Essentially it’s an array that holds the shape that we want, but it’s full of zeros, to do this, we use the following command:

import numpy as npnp.zeros((2,10))

This will create a 2 dimensional array with 10 zeros.

Copying Arrays

Another awesome trick we have with NumPy is creating deep copies of arrays, to do this, we use the .copy() function:

--

--