Thanks to both Roberto and George. I had considered the recursive solution but was worried about its efficiency. I had not seen how to implement the numpy solution, which looks pretty nice. Thanks! Alan