I am confused as to why this code:
start = time.time()
for i in range(1000000):
_ = 1 - np.log(X)
print(time.time()-start)
Executes faster than this implementation:
start = time.time()
for i in range(1000000):
_ = np.subtract(np.ones_like(X), np.log(X))
print(time.time()-start)
My understanding was that it should be the opposite, as in the second implementation I'm utilizing the speed-up provided by vectorization, since it's able to operate the elements in X simultaneously rather than going sequentially, which is how I assumed the first implementation functions.
Can someone shed some light on this for me, as I am genuinely confused? Thank you!