An Introduction to Scientific Programming in 2020 with Python


Spyder IDE

These guides will use the scientific python development environment abbreviated spyder as an Integrated Development Environment (IDE). This IDE has a user interface similar to matrix laboratory matlab and is one of the best IDEs for learning the fundamentals of python and usually the preferred IDE for data science. Spyder version 4.1.1 of later should be used as this version has a multitude of improvements over earlier versions. I give full instructions on performing a clean installation of Anaconda below:

Object Orientated Programming

Before moving onto the core scientific libraries numpy, pandas and matplotlib it is worthwhile getting your head around object-oriented programming.

Core Python Libraries for Data Science

The numpy Library

The numeric python library abbreviated numpy is the most commonly used python library. It is used for array manipulation.

The pandas Library

The python and data analysis library abbreviated pandas is one of the most commonly used libraries in data science. This library allows for dataframe or spreadsheet manipulation or in other words is in essence the Excel of python.

The matplotlib Plotting Library

The matplotlib library is the python plotting and data visualisation and is highly based on matlab/octave.

look at grid spec.

The scientific python Library

This library can be thought of as an extension to the numeric python library numpy.

Python Basics: Using the IPython Console As a Basic Calculator

In this guide we look at some of the fundamentals of core python such as datatypes. These are numerical – integers (whole numbers) and floats (numbers with a decimal point), strings (text input) and Boolean (logical – true or false). We also look at the assignment of variables and the use of elementary mathematics between scalars. Some basic functions are also introduced.

Python Basics: Scripts

Earlier we typed in all code in the IPython Console. Now we will have a look at using a script, with comments and how to print commands to the console.

Python Basics: 0 Order Indexing

Python uses 0 order indexing. When starting with Python (particularly if one is used to MATLAB). we need to spend a moment relearn how to count to get used to zero order indexing.

Python Basics: Dictionaries

Creating a dictionary and indexing from it. In this example we will create a dictionary of a custom colour palette and use it to print out coloured text in the console.

Python Basics: Scalars, Vectors and Matrices

In this guide we look further at some of the fundamentals of core python and examine numerical data in the form of a list. This list can be a scalar, vector, matrix, book or more complicated multi-dimensional array. We discuss some of the basics behind indexing and examining the dimensions of an array.

Python Basics: Lists, Tuples and Sets

Here we look at the concept of mutability (changeability) and discuss that sometimes this is not desirable. In such cases we create a tuple opposed to a list. We also have a look at sets.

MatPlotLib: Interpolation

In this section we look at a practical example. Here we practice linear algebra of matrices to interpolate a single point in a curve. We then see how we interpolate a series of points from a data curve using interpolation functions. This also reinforces some of the basics when it comes to plotting.

MatPlotLib: Curve Fitting

In this section we look at curve fitting using the polyfit and polyval functions. Again this gives practice for plotting and here we also introduce subplotting.

MatPlotLib: Trigonometry

Here we practice plotting using right angle triangles. We then plot a series of normalised right angle triangles on a circle to obtain the ratio of sides with respect to the angle. Then use rules of symmetry to obtain equally spaced values around the entire circle. This demonstrates the properties of the sin, cos and tan waveforms.

Python Intermediate: If (if), Else If (elif) and Else (else)

Here we discuss how to only run code only if a certain condition is met. We can also specify what code to run if the condition is not met and we can also express multiple conditions.

Python Intermediate: Creating a Custom Function

Here we will discuss how to define a custom function, how to load the custom function and how to run the custom function. We will discuss also the assignment of function input arguments and the creation of function output arguments.

Python Intermediate: For Loop

In this section we look at using a for loop to automate some repetitive tasks. We see how we can use a for loop to perform the same calculations for a series of lines in a variable or dataframe. We also touch upon using For Loops for plotting.

Python Intermediate: While Loop

In this section we compare a while loop to a for loop and then move on to combining a for loop with if, else if and else statements to create a homeostasic system.

MatPlotLib: Integration and Differentiation

Here we visualise how we perform integration, employing indexing, plotting techniques and for loops.

Python, NumPy and MatPlotLib: Image Processing Fundamentals

An image as discussed earlier is a 3D array with the 0th page being the intensity of the primary colour red for each pixel, the 1st page being the intensity of the primary colour green for each pixel, the 2nd page being the intensity of the primary colour blue and the 3rd page being the alpha or transparency. All other colours as discussed before are made up using different combinations of red, green and blue. We will look at importing a .png file, deconstructing this 3D array and performing some very basic photo editing by amending the numeric values in this 3D array.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.