Scientific coding in numpy#

So far we have only covered standard python for health data science. Its very important to develop your skills in standard python as you will undoubtedly use them the most. Beyond the standard library you will learn why python is an exciting and popular language in data science: there is a whole ecosystem of scientific libraries built around algorithms, modelling data manipulating, processing and visualision. The fundamental and in my view most important of these is numpy. The most important contribution of the numpy library is the concept of an efficient n-dimentional array.

I know what you are thinking: ‘why does python need an array when we already have lists and other similar data structures? The answer is simply speed of computation: numpy arrays are lightening fast relative to standard python. As you will learn, underneath the hood a list is very different from a numpy array.


“This is too much”

Its worth saying that in my view is this (enourmous) efficiency benefit does come with a trade-off. numpy does have a higher learning curve than standard python for new coders. When I first taught numpy it was part of a course in analytics introducing mathematics and business students to data science in python. After our first numpy computer lab my favourite quote from a group of distressed students was “this is too much… TOO MUCH” (it was actually shouted at me). numpy is less pythonic and it can at time be difficult to get the elegance of design you want matched with numpy code. However, for many mathemathical operations numpy code can be more readable due to a concept called ‘broadcasting’ that we shall cover in a later section. Do persevere if you find it difficult at first. To be clear if you are doing substantive computational work in python you should be using numpy and you need to know how to use it to be employable in health data science.

The material in the following sections has been designed to try and avoid my “too much, too much” problem. I hope you enjoy it. If you have any suggestions on what you need explaining do let me know.