I 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.
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.
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.
Version 0.3 of my Tkinter Pillow Application adds the ability to resize images, as well as Undo/Redo functionality. Versions 0.1 and 0.2 are here and here, and in this post I will just list the new code.
Everyone understands averages, both their meaning and how to calculate them. However, there are situations, particularly when dealing with real-time data, when a conventional average is of little use because it includes old values which are no longer relevant and merely give a misleading impression of the current situation.
The solution to this problem is to use moving averages, ie. the average of the most recent values rather than all values, which is the subject of this post.
In my post An Introduction to Image Manipulation with Pillow I commented that "You could in principle use it [Pillow] as the basis of a sort of lightweight Photoshop type application using perhaps Tkinter or PyQT". At the time I wasn't actually intending to do so but recently the idea has started to appeal to me so I thought I'd give it a go.
Although I'm not attempting to compete with Photoshop this is still a fairly ambitious project which will spread over a number of posts, and to start with I'll just get something very basic up and running.