np.random.seed(1)
a = np.random.rand(10000000) # very large arrays
b = np.random.rand(10000000)
tic = time.time() # capture start time
c = np.dot(a, b)
toc = time.time() # capture end time
print(f"np.dot(a, b) = {c:.4f}")
print(f"Vectorized version duration: {1000*(toc-tic):.4f} ms ")
I didn’t understand the use of {c:.4f}
what is .4f?
1 Like
Hey @Ayush_Kazi_Shrestha,
Welcome to the community.
It is used to control the number of decimals to be printed by the print
statement in Python for floating-point values. For instance, consider the following Python code:
variable = 10 /3
print(variable)
print(f"{variable:.4f}")
It will result in the following output,
3.3333333333333335
3.3333
Let me know if it helps.
Cheers,
Elemento
1 Like
Hey @rmwkwok,
If I am not wrong, you wrote an elaborated reply regarding this exact issue recently. Can you please provide the link to that thread? I am unable to find that thread.
Cheers,
Elemento
Hey @rmwkwok, thanks a lot for sharing this. @Ayush_Kazi_Shrestha, please do check this thread out for further information.
Cheers,
Elemento
1 Like
Thank you, I get it now. @Elemento