Lightweight, easy-to-use app for university podcast access.

Linear Algebra and Sandwiches

Recently an interesting course opened up on Coursera (A free course system similar to iTunesU, with the added benefit of certificate with completion of a course).

In Coding the Matrix: Linear Algebra through Computer Science Applications, they give a really good intro to basic Python programming – and mathematical programming in Python3. If, like me you have been using python 2.x (which Tunesviewer is written in), you may notice a few differences:

  • Python3 is consistent with print function, it requires parentheses as other functions do.
  • Division works more consistently like other languages – 7/3 isn’t different than 7/3.0 for example. (Note that you can have this behavior in 2.x by running “from __future__ import division” at top of your script file)
  • Some libraries have changed to simpler names, use of dictionaries is perhaps easier with “mykey in dictionary” instead of “dictionary.has_key(mykey)” (although “in” keyword is sort of doing two different operations, existence of element and iteration in for loops 🙁 )

You’ll notice even in the first week of the course they have some practical applications – list comprehensions and sets.

You can, for example, use cartesian product to help you choose from all combinations of sandwiches you could make:

breads = [‘rye’, ‘wheat’, ‘white’, ‘spelt’]
fillings = [‘pb’, ‘avocado’, ‘honey’, ‘cream cheese’]
{b,f for b in breads for f in fillings}

This will output:

{(‘white’, ‘pb’), (‘white’, ‘avocado’), (‘rye’, ‘cream cheese’), (‘wheat’, ‘honey’), (‘spelt’, ‘cream cheese’), (‘white’, ‘cream cheese’), (‘wheat’, ‘avocado’), (‘rye’, ‘avocado’), (‘spelt’, ‘avocado’), (‘spelt’, ‘pb’), (‘wheat’, ‘pb’), (‘wheat’, ‘cream cheese’), (‘rye’, ‘pb’), (‘spelt’, ‘honey’), (‘rye’, ‘honey’), (‘white’, ‘honey’)}

Share - Share on RedditEmail this to someoneShare on Google+Tweet about this on TwitterPin on PinterestShare on StumbleUponShare on Facebook

Posted in News

Comments are currently closed.