Vectorized version with Numpy