Update numpy code to make it faster