This is an archived version of the course. Please see the latest version of the course.

Introduction to NumPy

Hello! It’s me, Josiah, and I will be your guide through this tutorial.

In this tutorial, we will look at NumPy, a Python package that is used for scientific computing.

I have prepared this module as an introduction. I will not be able to cover every single feature of NumPy (and won’t), so please do refer to the official documentation to explore all the nitty gritty details that NumPy offers. I will only focus on features that you will most likely use to get you through most tasks.

NumPy

NumPy is a Python scientific computing package, which allows you to do large-scale multi-dimensional array operations easily and efficiently, and provides many Mathematical and Scientific libraries to help you perform scientific computations easily.

If you are an experienced MATLAB user

For the MATLAB/Octave users among you, everything will seem familiar. NumPy tries to emulate the features in MATLAB, but in a Pythonic way. The two main things you have to remember as MATLAB users are:

  • indices start at 0 in NumPy, not 1 as in MATLAB
  • use square brackets [] to access elements instead of paranthesis ().

You can refer to this quick tutorial that gives you a summary of how to do MATLAB-y things in NumPy. Then feel free to just get cracking and experimenting!

Importing NumPy

To use NumPy:

import numpy as np

It is common to use np as a shorthand. We will assume this import and use np in all the examples that will follow.

If you get a ModuleNotFoundError, then you will have to first install NumPy.

$ pip3 install numpy