Also, after much debugging, the memory leaks and segfaults (well...those that I know about so far) are coming from numpy.linalg.lstsq. Give up on the guessing, and set beta to 0 initially.