A first crack at converting the matlab code, should be careful to check how matlab and numpy deal with dimensions, and more specifically, the broadcasting of arrays.