Archive for February, 2011

Python numpy moving average for data

The following examples produces a moving average of the preceding WINDOW values. We truncate the first (WINDOW -1) values since we can’t find the average before them. (The default behaviour for convolution is to assume that values before the start of our sequence are 0). (More formally, we construct the sequence y for the sequence x where y_i = (x_i + x_(i+1) + …. x_(i+n)) / n)

WINDOW = 10
data = [1,2,3,4,5,5,5,5,5,5,5,5,5,5,5]
weightings = numpy.repeat(1.0, WINDOW) / WINDOW
numpy.convolve(data, weightings)[WINDOW-1:-(WINDOW-1)]

This makes use of numpy’s convolution function. This is a general purpose moving average operation.

Changing weightings makes some values more important; offsetting appropriately allows you to view average as around point rather than before point.

Rather than truncating values we can fix the initial values in place, as illustrated in this example:

WINDOW = 10
data = [1,2,3,4,5,5,5,5,5,5,5,5,5,5,5]
extended_data = numpy.hstack([[data[0]] * (WINDOW- 1), data])
weightings = numpy.repeat(1.0, WINDOW) / WINDOW
numpy.convolve(extended_data, weightings)[WINDOW-1:-(WINDOW-1)]

February 24, 2011 at 11:58 pm 5 comments

Setting the minimum values for axes in matplotlib

pylab.axis(xmin=0, ymin=0)

February 24, 2011 at 11:28 pm Leave a comment

Making 3 Mobile Broadband work with googlemail (and other sites)

It appears that people in the london area have been having issues with timeouts using 3 Mobile broadband for the last month or so

http://www.3g.co.uk/3GForum/showthread.php?t=99773

Someone on this forum found a work around – but forums lack readability and everything good be rather clearer.

Symptoms: Connection seems to mostly work but some https sites simply timeout (in particular wordpress and google mail)

Causes: This has something to do with MTU discovery.

Solution: Lower your mtu

On windows this can be done by:

* Opening a command as an administrator (Type cmd into the start bar, then select the shell and press ctrl-shift-enter)
* Typing “netsh interface ipv4 show subinterfaces” to list all connections, and identify the three connection.
* Typing “netsh interface ipv4 set subinterface “3Connect (or similar)” mtu=700″

See http://www.richard-slater.co.uk/archives/2009/10/23/change-your-mtu-under-vista-or-windows-7/ for more details.

I’m going to send three an e-mail. I wonder how long it will take them to fix this.

February 15, 2011 at 12:32 am Leave a comment


February 2011
M T W T F S S
 123456
78910111213
14151617181920
21222324252627
28