Skip to content

Instantly share code, notes, and snippets.

View aeberspaecher's full-sized avatar

Alexander Eberspächer aeberspaecher

View GitHub Profile
@aeberspaecher
aeberspaecher / scatterPlot.py
Created August 7, 2012 10:12
Nice scatter plots with Matplotlib
#!/usr/bin/env python
#-*- coding:utf-8 -*-
"""Test different hollow Matplotlib markers for scatter plots.
Imitate Gnuplot a bit.
"""
#import matplotlib
#matplotlib.use("module://backend_pgf")
@aeberspaecher
aeberspaecher / sampler.py
Created June 19, 2012 09:30
Random variates from a discretly sampled two-dimensional probability density function
"""Sample random numbers according to a uniformly sampled 2d probability
density function.
The method used here probably is similar to rejection sampling
(http://en.wikipedia.org/wiki/Rejection_sampling).
"""
import numpy as np
import sys
from scipy.interpolate import RectBivariateSpline
@aeberspaecher
aeberspaecher / runCython.py
Created January 20, 2012 10:02
Run the Hailstone code
from hailstoneCython import hailstone
if __name__ == '__main__':
h = hailstone(27)
assert len(h)==112 and h[:4]==[27, 82, 41, 124] and h[-4:]==[8, 4, 2, 1]
print("Maximum length %i was found for hailstone(%i) for numbers <100,000" %
max((len(hailstone(i)), i) for i in range(1,100000)))
@aeberspaecher
aeberspaecher / hailstoneCython.pyx
Created January 20, 2012 10:02
Hailstone sequence in Cython
"""Hailstone sequence.
"""
# compile with
# cython hailstoneCython.pyx
# -O2 -shared -fPIC -march=native -IPATH_TO_PYTHON.H -o hailstoneCython.so hailstoneCython.c
cpdef list hailstone(int n):
cdef list seq
seq = [n]
@aeberspaecher
aeberspaecher / 00README.rst
Created September 30, 2011 13:10 — forked from GaelVaroquaux/00README.rst
Copy-less bindings of C-generated arrays with Cython

Cython example of exposing C-computed arrays in Python without data copies

The goal of this example is to show how an existing C codebase for numerical computing (here c_code.c) can be wrapped in Cython to be exposed in Python.

The meat of the example is that the data is allocated in C, but exposed in Python without a copy using the PyArray_SimpleNewFromData numpy