[Numpy-discussion] How to speed up this function?