Should you always use an IDE to write software? Is it sometimes good to get back to a simple text editor and command lines tools?

Continue reading

Should you always use an IDE to write software? Is it sometimes good to get back to a simple text editor and command lines tools?

Continue readingI recently wrote a post on RGB/HSL Conversions in Python and as a follow-up I decided to put together a simple Tkinter application which enables users to display a colour by selecting any combination of hue, saturation and lightness.

This application is only a toy but playing with it for a few minutes does give an intuitive understanding of the HSL system, and reinforces my conviction that it is easier to comprehend than RGB. And if you have never used Tkinter this project also provides a simple introduction to the topic.

Continue readingA while ago I wrote a post called Colour Converter in C about converting RGB (red/green/blue) values to HSL (hue/saturation/lightness) and back again. As part of a project which I am planning I need to be able to do the same in Python and was intending to re-write the C in Python, or probably Cython. However, I then found a module called colorsys in an obscure corner of the Python Standard Library. This module includes functions to do the conversions I will need, and in this post I will demonstrate using them to create an array of HSL values from a Pillow image, and then convert these back to RGB to create a new identical image.

Continue reading

In previous posts I have covered Creating a PostgreSQL Database in C and PostgreSQL Data Manipulation in C. In this post I will write and demonstrate a few simple functions which use the libpq library's PQprint function to export data to the terminal, HTML and CSV files.

Continue reading

Graph Theory is a vast area of study based around the simple idea of individual points - known as vertices - connected by lines known as edges, each of which may have an associated numeric values called a weight and perhaps also a direction.

These simple sets of vertices, edges, weights and directions are known as graphs (not to be confused with the more familiar graph of data or a mathematical function) and can be used to represent many real-world situations or abstract concepts. Once you have a graph stored in some kind of data structure there are many algorithms which can be applied to solve problems, especially those of optimisation.

This post is the first of potentially many, and in it I will develop a data structure to store a graph. In future posts I will implement some of the algorithms which operate on graphs.

Continue reading

If you need to carry out any serious work with matrices in Python then your best option will usually be to use the NumPy package. NumPy provides an industrial strength array class called ndarray (n-dimensional array) which can be used to represent a matrix, and the usual arithmetic operators can be used. Additionally, you can use the @ operator to multiply two matrices together.

However, if you are trying to learn matrix arithmetic then NumPy isn't going to help much as matrix operations aren't very intuitive, especially matrix multiplication which is rather convoluted. The best way to learn is probably to start with a sheet of paper and a pen, working through some examples, before moving on to writing code from scratch to perform the various arithmetic functions.

In this post I will write a very quick whistlestop tour of matrix arithmetic using NumPy before moving on to the main purpose of this post: writing a simple matrix class from scratch.

Continue reading

In this post I will implement a simple Noughts and Crosses game, sometimes known as Tic Tac Toe.

Continue reading

One of the most useful bits of number-crunching you can do is to calculate the probability distribution of a set of data in the earnest hope that it will be a reasonable fit for one of the recognised distributions such as the normal distribution. In this project I will write a Python class to calculate the normal distribution for a given data set.

Continue reading

Some time ago I wrote a post on calculating a selection of statistics from a list on numbers. I got some criticism from people saying that for some of the statistics I should have used Python built-in functions or functions from the Python Standard Library statistics module.

Doing so, however, would cause each of those functions to iterate over the entire dataset. If you want to calculate a number of different statistics in one go you can increase efficiency considerably with just one iteration.

I started writing a simple experiment to calculate the minimum, maximum, sum, mean and standard deviation of a list of numbers using Python's own functions, calculating them again using a single loop, and then comparing the performance.

I then decided to expand the experiment somewhat, firstly by running the plain Python code with PyPy instead of CPython, and then re-writing the Python as Cython. This article explores these experiments and presents the results.

Continue reading

In a previous post I introduced the libpq PostgreSQL C library and used it to create a database, a few tables and a view. In this post I will demonstrate inserting, updating, deleting and selecting data using the database created in the previous post.

Continue reading