I'm trying to improve the performance of some rather large code. One of the bottlenecks is the line below. It doesn't look like much but it is processed millions of times.
Is there any way to improve its performance at the code level (ie: no parallelization)? I'm perfectly fine with the final outcome being a
numpy array instead of a list.
import numpy as np def func(m1, m2): return -2.5 * np.log10(10 ** (-0.4 * m1) + 10 ** (-0.4 * m2)) # Generate data. N1, N2 = 300, 200 aa = np.random.random((5, N1)) idxs = np.random.choice(N1, N2, replace=False) bb = np.random.random((10, N2)) # I need to improve the performance of this line. cc = [func(m[idxs], bb[i]) for (i, m) in enumerate(aa)]
As Mibac suggested, the issue here might actually be the successive calls to
func(), not the generation of the
cc list itself.
If this is the case, then I'd need to improve the performance of the line:
-2.5 * np.log10(10 ** (-0.4 * m1) + 10 ** (-0.4 * m2))
-2.5 * np.log10(c ** m1 + c ** m2)