## Delete MATLAB #2: Slice Notation

Part 2 in an irregular series about migrating from MATLAB to Python. Slice notation allows you to quickly take a subset of a vector or matrix, by using a short expression in place of the indices. In MATLAB you may be familiar with >> a = [1,2,3,4,5,6,7,8,9,10]; >> a(3:7) ans = 3 4 5 6 … [Read more…]

## Welcome to the Grand Hotel, Please Excuse our Appearance

Memo to All Guests As you know, we recently embarked on an exciting renovation to expand the Grand Hotel. If you have stayed with us before, you may have noticed that your room numbers are now represented by real numbers, rather than just integers. Many guests have remarked how much they like the new numbering … [Read more…]

## On digital archaeology

The year is 4018. German is widely studied by scholars of classical antiquity, but all knowledge of the mysterious English language has died out. Scene: A classics department faculty lounge; a few professors are relaxing.  Prof 1 [rushes into the room]: Guys! Guys! You remember that cache of magnetic recordings they found in the ruins … [Read more…]

## Delete MATLAB #1: pyplot does LaTeX

My resolution for 2018 (well, one of them) is to delete MATLAB and migrate to Python. Here’s one very good reason: the pyplot package does basically everything you need for plotting, plus you can write axis labels and legends in LaTeX. Here’s some example code (remember this is best done in Anaconda): import matplotlib.pyplot as … [Read more…]

## “Intensity” channels

Consider a random variable x taking discrete values $$x \in \{x_1,x_2,\ldots,x_n\},$$ with probability mass function $$p(x_i).$$ If all the possible values of x are positive, it turns out that the following is also a valid probability mass function (all positive, sums to 1): $$q(x_i) = p(x_i) \frac{x_i}{E[X]},$$ where $$E[X] = \sum_i x_i p(x_i)$$ is the expected value of x. … [Read more…]

## Knuth shuffle

The Knuth shuffle is a simple, elegant algorithm for randomly permuting a list. It’s not used very often, but it’s one of my favourite algorithms. Here’s how it works: for a list n with elements n, n, …, n[N-1], pick an index uniformly distributed over 0,1,…,N-1. That index is swapped with n. (If you pick … [Read more…]

## Resolution for 2018: Delete MATLAB

Over the past year or so, I’ve been migrating from MATLAB to Anaconda, a free distribution of Python. With the NumPy and PyPlot packages, Anaconda keeps the functionality of plain-vanilla MATLAB while adding the power of the Python language. And if you like graphical IDEs, Anaconda includes Spyder, which replaces the MATLAB graphical environment. Over … [Read more…]