Skip to content

Instantly share code, notes, and snippets.

@alexalemi
Created November 3, 2011 21:10
Show Gist options
  • Save alexalemi/1337792 to your computer and use it in GitHub Desktop.
Save alexalemi/1337792 to your computer and use it in GitHub Desktop.
Checkerboard Permutation
import numpy as np
from itertools import permutations
foo = np.arange(25).reshape(5,5)
def permuteevens(A):
mask = np.fromfunction(lambda i,j: (i+j)%2==0, A.shape )
vals = A[mask]
for p in permutations(vals):
A[mask] = p
yield A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment