def bin_perm_rep(ndim, a=0, b=1):
 nperms = (2 ** ndim)
 perms = np.empty((nperms, ndim), type(a))
 perms.fill(a)
 half_point = (nperms // 2)
 perms[half_point:, 0] = b
 for j in range(1, ndim):
  half_col = perms[::2, (j - 1)]
  perms[:half_point, j] = half_col
  perms[half_point:, j] = half_col
 return perms

def bin_perm_rep ( ndim , a = 0 , b = 1 ) : nperms = ( 2 ** ndim ) perms = np . empty ( ( nperms , ndim ) , type ( a ) ) perms . fill ( a ) half_point = ( nperms // 2 ) perms [ half_point : , 0 ] = b for j in range ( 1 , ndim ) : half_col = perms [ : : 2 , ( j - 1 ) ] perms [ : half_point , j ] = half_col perms [ half_point : , j ] = half_col return perms
ndim permutations with repetitions of .