Coding the Simplex Algorithm from scratch using Python and Numpy

Jake
9 min readDec 21, 2018
Image credit: wikipedia creative commons license

If your introduction to data science began anything like mine, your first exposure to numpy went something like this: “Pandas is super is useful. It’s built on this other library called numpy but you only need to know the bare minimum of that to get up and running with Pandas.” Over the last year, I’ve brushed up on numpy every month two, but it was always a few simple exercises like ‘try indexing by column or row’ — just to make sure you got the concepts.

But I had rarely needed to use for loops on a numpy array, grab the index of a particular element based on satisfaction of boolean statements, or any numpy problem that required strained attention. Ergo I decided to use a fun project as a means to improve my technique and mastery of numpy.

If you’re unfamiliar with the simplex algorithm — you’re missing out. It was invented in 1946–1947 by George B. Dantzig as a means to solve linear optimization problems. For example, imagine that you’re a carpenter; you make chairs, tables, and desks for a living. Each item requires x, y, and z labor hours worth of sanding, upholstering, and finishing. And you have a fixed number of labor hours available for each task (sanding, upholstering, and finishing.) If tables, chairs, and desks bring in a, b, and c dollars — which combination of furniture should you produce each…

--

--

Jake

Amazon Scientist, author/blogger, and continual learner