Beginner’s Guide to NumPy: A Must Have Python Library in Data Scientist Toolkit

NumPy, which stands for Numerical Python, is a fundamental library for mathematical computations. This library can be used for different functions in Linear algebra, Matrix computations, Fourier Transforms etc. In Python, array.array function is limited to only one dimension which can be substituted with NumPy for multi dimensional operations. One can compute the multidimensional array functions like the figure below,

THE BELAMY

In this article we will go through some of the important built-in function of NumPy to understand the logic and mathematics behind it. By using NumPy, you can speed up your workflow, and interface with other packages in the Python ecosystem, like scikit-learn, that use NumPy under the hood. Let us dive into computing the math behind these.

1. Arrays

An array is a set of elements of a data type. The shape of the NumPy array can be defined with an enclosed tuple of positive integers. The order of a NumPy array is given by the dimensions. We can index and slice a particular element from the array, and initialize an array with square brackets like below,

2. Indexing

Like Python lists, the Numpy array can be indexed and sliced with the right number of parameters. It can be done as described below,

3. Slicing

Index slicing is as it sounds, slicing one or multi dimensional array into different subsets like below example,

With the use of negative numbers, we can compute the functions in the reverse order like the example below,

Let us consider a multi-dimensional array and try to slice it.

We can implement the following code to slice it,

4. Matrix Algebra

After these steps, matrix multiplication is important, which can be done in two ways. We can either use the dot function, which applies a matrix-matrix, matrix-vector, or inner vector multiplication to its two arguments:

5. Matrix Computations

Functions such as finding the inverse of a matrix and determinant of a matrix can also be done with NumPy like below,

6. Statistical Computations

Most of the times it is useful to store datasets in NumPy arrays. It provides a number of functions to calculate statistics of datasets in arrays. Let us calculate some properties of the matrix B,

More Great AIM Stories

OOPs! The Programming Blooper That Became Mainstream

Kishan Maladkar holds a degree in Electronics and Communication Engineering, exploring the field of Machine Learning and Artificial Intelligence. A Data Science Enthusiast who loves to read about the computational engineering and contribute towards the technology shaping our world. He is a Data Scientist by day and Gamer by night.

AIM Upcoming Events

Regular Passes expire on 3rd Mar

Conference, in-person (Bangalore)
Rising 2023 | Women in Tech Conference
16-17th Mar, 2023

Early Bird Passes expire on 17th Feb

Conference, in-person (Bangalore)
Data Engineering Summit (DES) 2023
27-28th Apr, 2023

Conference, Virtual
Deep Learning DevCon 2023
27 May, 2023

Telegram group

Discover special offers, top stories, upcoming events, and more.

Discord Server

Stay Connected with a larger ecosystem of data science and ML Professionals

Alphabet’s 2021 year in review: What propelled the 40% growth

This was CapitalG’s sixth IPO in 2021, after UiPath, Duolingo, Robinhood and Oscar.

Council Post: Generalists—The building blocks of a data science organisation

The ambition and inclination for continuous learning set the generalists apart as an invaluable resource in organisations.

Top 5 artificial intelligence APIs in 2022

Azure Cognitive Services enables developers and data scientists of all skill levels to add AI capabilities to their apps easily.

India is uniquely positioned to be the foundry for digital innovation: Shailendra Saxena, EY GDS

We are using a combination of RPA, AI/ML and other technologies to augment the workforce and enhance the user experience on each service we offer.

What went wrong with Meta?

Many users have opted out of Facebook and other applications tracking their activities now that they must explicitly ask for permission.

How tech companies performed in the latest quarter

The Tim Cook-led company beat analyst estimates on sales of every product category except iPads.

New research on enabling a vision-based robotic manipulation system

The Google AI study concluded that robots could use the BC-Z system to complete 24 new tasks with an average success rate of 44%.

Top resources to learn quantum machine learning

We will take a look at a few online resources one can use to learn quantum machine learning.

How to perform fast and explainable clustering using CLASSIX?

Clustering is the process of putting items together so that members of the same group (cluster) be more common with their peers than members of other groups.

Copilot vs AlphaCode: The race for coding supremacy

Deepmind’s AlphaCode made headlines by testing in the top 54% of human coders. Can GitHub’s Copilot keep up with AlphaCode’s automated programming?