This is an archived version of the course and is no longer updated. Please find the latest version of the course on the main webpage.

Introduction to NumPy

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

Towards the end of the module, we will also briefly look at Matplotlib, a Python visualisation toolkit for plotting graphs, figures etc.

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 as NumPy sort of try 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.