So you have a list of tuples, created with the zip built-in function in Python. Like this:

z = [(1, 'a'), (2, 'b'), (3, 'c')] |

And you want to reverse zip, to get these two lists:

x = [1, 2, 3] y = ['a', 'b', 'c'] |

Skip to content
# Category: Programming

## Python: inverse of zip

## How to convert numpy matrix with different floats to matrix with zeros and ones

## Plotting data on maps with matplotlib

## Geographical plots

## Heatmaps

## Making your Python code installable with PIP

## Trying SQLAlchemy for Python

## Install SQLAlchemy

## Learn SQLAlchemy

## How to install gfortran on Mac OS X

## Install

## Calling __init__() on all base classes in Python multiple heritance

## Getting up to speed with Git

## Simulating the Golden Balls game show

## Simple programs for simple turing machines

trying stuff with code

So you have a list of tuples, created with the zip built-in function in Python. Like this:

z = [(1, 'a'), (2, 'b'), (3, 'c')] |

And you want to reverse zip, to get these two lists:

x = [1, 2, 3] y = ['a', 'b', 'c'] |

Given a numpy matrix (`mixed_float_matrix`) with a variety of float values, how do you convert it into a matrix, with zeros and ones (ones in place of non-zero values in the original matrix)?

Continue reading “How to convert numpy matrix with different floats to matrix with zeros and ones”

I’m learning about matplotlib, and actually just bought the book Matplotlib for Python Developers.

Browsing stackoverflow, the matplotlib homepage, and other resources, I eventually came by this stackoverflow post, which mentions BaseMap. Since the data that I’m plotting is inherently geographical, it makes sense to show the data on a map.

There are several nice examples on the basemap Github page.

Often I want to create heatmaps of the data, using matplotlib.

On stackoverflow there are several posts on this topic:

- Generate a heatmap in MatPlotLib using a scatter data set
- pyplot: really slow creating heatmaps
- Generate a heatmap in MatPlotLib using a scatter data set

There are different colormaps available for matplotlib, if you want to try different colorschemes.

I like to install 3rd party Python libraries using pip. Pip and easy_install can automatically download and install Python code from PyPi (also known as The Cheese Shop). This is how to publish your own Python code on PyPi, so people can do this:

`pip install yourawesomeproject` |

Continue reading “Making your Python code installable with PIP”

This is easy (using pip):

`pip install sqlalchemy` |

http://docs.sqlalchemy.org/en/latest/core/tutorial.html

This tutorial uses an in memory SQLite database, which is cool in itself.

Various topics:

Why did I install gfortran? Well, not to write Fortran programs. I tried installing SciPy using `pip install scipy`, and I got a message that a Fortran compiler was needed.

This is how I installed gfortran on my Mac:

Visit hpc.sourceforge.net, and select a binary distribution for your version of Mac OS X, e.g. gfortran-snwleo-intel-bin.tar.gz for Snow Leopard.

Here is an example of calling

__init__() |

for all base classes, when doing multiple inheritance in Python (mixins). It uses *args and **kwargs syntax:

Continue reading “Calling __init__() on all base classes in Python multiple heritance”

This is how you can get started successfully using Git.

- Basic concepts:

Git Tutorial (by Lars Vogel) - how successful developers are using Git:

A successful branching model for Git (Gitflow) - Online books:

Pro Git and Git Community Book

Additional things to read:

In this eposide of Golden Balls, an inspired event takes place:

I retold the event at DIKU APL lunch (nice to have a job where game theory is a valid conversation topic), and we had a conversation about it. At first I thought this was prisoners dilemma, but it was quickly revealed that it is a different game. What is cool about it is, that Nick basically forces Abraham to pick split. I don’t think the same approach would work again though. The person in Abrahams position might be tempted to try a counter-steal. The person in Nicks position might be tempted to actually steal the money, which would be a dirty thing to do, but not completely unlikely.

I’ve always wanted to understand Turing Machines better. I believe that the best understanding comes from the intuition developed by solving puzzles.

So here, I give myself some challenges. Solve simple problems by writing programs for a simple Turing Machine, using this simulator: http://ironphoenix.org/tril/tm/

Continue reading “Simple programs for simple turing machines”