简体   繁体   中英

Number of loops in Numpy Element wise operation

I am taking element wise power of a numpy array as well as a python list. Why are there 10000 loops for the numpy operation?

In [1]: a = np.arange(1000)

In [2]: %timeit a**5
10000 loops, best of 3: 77.8 µs per loop

In [3]: b = range(1000)

In [4]: %timeit [i**5 for i in b]
1000 loops, best of 3: 1.64 ms per loop

From the documentation ( https://docs.python.org/2/library/timeit.html#command-line-interface ):

If -n is not given, a suitable number of loops is calculated by trying successive powers of 10 until the total time is at least 0.2 seconds.

In other words, timeit runs your statement 10000 times because that's about how many it can do in .2 seconds. It has nothing to do with the number you passed to arange .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM