Looking for a code review, and hopefully to learn something if someone has a nicer solution.  Here's what I wrote:from __future__ import division, print_functionfrom future_builtins import *import numpy as npdef _walk(num_dims, samples_per_dim, max_):    if num_dims == 0:        yield np.array([(max_ - 1) / (samples_per_dim - 1)])    else:        for i in range(max_):            for rest in _walk(num_dims - 1, samples_per_dim, max_ - i):                yield np.concatenate((np.array([i]) / (samples_per_dim - 1),                                      rest))def walk(num_dims, samples_per_dim):        A generator that returns lattice points on an n-simplex.        return _walk(num_dims, samples_per_dim, samples_per_dim)So, list(walk(2, 3)) yields:[array([ 0.,  0.,  1.]), array([ 0. ,  0.5,  0.5]), array([ 0.,  1.,  0.]), array([ 0.5,  0. ,  0.5]), array([ 0.5,  0.5,  0. ]), array([ 1.,  0.,  0.])]
Python generator to produce lattice points on an n-simplex.
python;generator
Using Winston Ewert's suggestions of using itertools, and using lists instead of numpy arrays internally, here's an alternate solution:def walk(num_dims, samples_per_dim):        A generator that returns lattice points on an n-simplex.        max_ = samples_per_dim + num_dims - 1    for c in combinations(range(max_), num_dims):        c = list(c)        yield [(y - x - 1) / (samples_per_dim - 1)               for x, y in izip([-1] + c, c + [max_])]