Why is x**3 slower than x*x*x?
In NumPy, x*x*x is an order of magnitude faster than x**3 or even
np.power(x, 3).
x = np.random.rand(1e6)
%timeit x**3
100 loops, best of 3: 7.07 ms per loop
%timeit x*x*x
10000 loops, best of 3: 163 µs per loop
%timeit np.power(x, 3)
100 loops, best of 3: 7.15 ms per loop
Any ideas as to why this behavior happens? As far as I can tell all three
yield the same output (checked with np.allclose).
No comments:
Post a Comment