Python's Sum or NumPy's np.sum() ???I found a big difference in time!!
Adityaberi
Posted on May 4, 2020
According to me
Use python's methods (sum()) on python datatypes and use NumPy's methods on NumPy arrays (np.sum()).
massive_array=np.random.random(100000)
massive_array.size
100000
massive_array
array([0.81947279, 0.24254041, 0.76437261, ..., 0.15969415, 0.34502387,
0.15858268])
%timeit sum(massive_array) #Python sum
%timeit np.sum(massive_array) #Numpy sum
16 ms ± 494 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
50.6 µs ± 4.83 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)
That's a massive difference!!
What do you guys think???
💖 💪 🙅 🚩
Adityaberi
Posted on May 4, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.