Created
November 28, 2013 19:34
-
-
Save lucastheis/7697118 to your computer and use it in GitHub Desktop.
Demonstrates the problem with matplotlib resetting the random seed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from distutils.core import setup, Extension | |
modules = [ | |
Extension('_test', | |
language='c++', | |
sources=[ | |
'test.cpp'])] | |
setup( | |
name='test', | |
version='0.0.1', | |
author='Lucas Theis', | |
author_email='lucas@theis.io', | |
ext_modules=modules) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Python.h> | |
#include <stdlib.h> | |
#include <iostream> | |
using std::cout; | |
using std::endl; | |
PyObject* test(PyObject*, PyObject*, PyObject*) { | |
cout << rand() % 100 << endl; | |
cout << rand() % 100 << endl; | |
cout << rand() % 100 << endl; | |
cout << endl; | |
Py_INCREF(Py_None); | |
return Py_None; | |
} | |
static PyMethodDef test_methods[] = { | |
{"test", (PyCFunction)test, METH_NOARGS, 0}, | |
{0} | |
}; | |
PyMODINIT_FUNC init_test() { | |
Py_InitModule3("_test", test_methods, 0); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from numpy.random import randn | |
from matplotlib.pyplot import imsave | |
from _test import test | |
I = randn(128, 128) | |
imsave('test.png', I) | |
test() | |
imsave('test.png', I) | |
test() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment