Trying to vectorize the nupy code