Fastest way to calculate exponential [exp()] function of large complex array in Python
Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Luau
--
Chapters
00:00 Question
01:16 Accepted answer (Score 4)
01:43 Thank you
--
Full question
https://stackoverflow.com/questions/4652...
Accepted answer links:
[numexpr]: http://numexpr.readthedocs.io/en/latest/...
[expected performance]: http://numexpr.readthedocs.io/en/latest/...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #numpy #optimization #ode #numba
#avk47
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Luau
--
Chapters
00:00 Question
01:16 Accepted answer (Score 4)
01:43 Thank you
--
Full question
https://stackoverflow.com/questions/4652...
Accepted answer links:
[numexpr]: http://numexpr.readthedocs.io/en/latest/...
[expected performance]: http://numexpr.readthedocs.io/en/latest/...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #numpy #optimization #ode #numba
#avk47
ACCEPTED ANSWER
Score 4
We could leverage numexpr module, which works really efficiently on large data involving transcendental operations -
In [91]: arr = np.random.rand(2**14) + 1j *np.random.rand(2**14)
...: float_value = 0.5
...:
In [92]: %timeit np.exp(float_value * arr)
1000 loops, best of 3: 739 µs per loop
In [94]: import numexpr as ne
In [95]: %timeit ne.evaluate('exp(float_value*arr)')
1000 loops, best of 3: 241 µs per loop
This seems to be coherent with the expected performance as stated in the docs.