Migrating to Python from Matlab