Here is an example of calling

__init__() |

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

Skip to content
### skipperkongen

#
Programming

## 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

## Hooking into the whole Python way of distributing code

## Three good StackOverflow answers on Python topics

## Creating visually random images

## Incrementing part of an array in numpy

## Hello world of raster creation with GDAL and Python

## Using Cython, psyco and other tricks to make Python run faster

trying stuff with code

Here is an example of calling

__init__() |

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

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/

I'm just getting into this topic, but it seems that Python Eggs are the way to go. Here's a good tutorial:

http://mrtopf.de/blog/en/a-small-introduction-to-python-eggs/

In the long term, I'd like to be able to do:

pip install <name of python lib I've made> |

And host my code on PyPi etc.

Here are three thorough answers on Python topics from StackOverflow.

How complicated does a mathematical function, pseudorandom(x), have to be to create something that seems random, and how do you check whether it seems random? Looking at a long list of numbers is not a good way, because our ability to look at long lists of numbers is very limited. Our ability to look at images is much better.

So, to inspect whether a list of numbers is seemingly random, a fun way is to create an image using the numbers for each pixel, and simply look at it.

Given a number *x* in the series {0, 1, 2, ..., huge n}, let's create an image that plots a random function that's implemented using the sin() function and a 3rd degree polynomial function:

color_range = 2**8 a = -3.0 b = -5.0 c = 13.0 def pseudo_randombit(x): color255 = math.sin(a*x**3 + b*x**2 + c*x) % color_range # make black/white bit = color255 / 127 return bit |

given a (2D) array *a*, and a smaller (2D) array *b*, how can you add the smaller array to the bigger array at some offset in numpy?

>>> a = zeros((4,4), dtype=int) >>> a array([[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]) >>> b = ones((2,2), dtype=int) >>> b array([[1, 1], [1, 1]]) >>> a[1:3,1:3] += b >>> a array([[0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0]]) |

Mostly so I myself can remember how to do it, here is how to create a random geotiff with GDAL in Python

**Note**: the width and height are given in opposite order in the GDAL raster and numpy arrays!

import osr import numpy import gdal import math width = 4000 height = 3000 format = "GTiff" driver = gdal.GetDriverByName( format ) dst_ds = driver.Create( "test.tiff", width, height, 1, gdal.GDT_Byte ) dst_ds.SetGeoTransform( [ 444720, 30, 0, 3751320, 0, -30 ] ) srs = osr.SpatialReference() srs.ImportFromEPSG(25832) dst_ds.SetProjection( srs.ExportToWkt() ) raster = numpy.zeros( (height, width), dtype=numpy.uint32 ) color_range = 2**8 seed = math.pi**10 for i in range(height): for j in range(width): color = (seed*i*j) % color_range raster[i][j] = color dst_ds.GetRasterBand(1).WriteArray( raster ) |

It's kind of slow, so perhaps the operation can be speeded up somehow? The result looks kind of nice though (image created with width and height both 4000):

So, not completely random.

This is a good post showing how "perrygeo" uses Cython to speed up a pure Python function. The comments also discuss alternatives and options:

- Using psyco instead of Cython
- Using optimization flags for gcc
- Using xxx instead of math.xxx