-, Numpy. , .
def loglike(xs):
n = len(xs)
return -0.5 * n * np.log(2 * np.pi * np.std(xs)) - 0.5 * n
, nanstd, . , np.log math.log, , xs - , xs.std() . , , , .
Edit
loglike python -m cProfile -o output yourprogram.py; runsnake output, , ( 80%) np.std. . , - bottleneck.nanstd.
import bottleneck as bn
def loglike(xs):
n = len(xs)
return -0.5 * n * np.log(2 * np.pi * bn.nanstd(xs)) - 0.5 * n
8 , 30% . len 5%, . np.log np.pi , .
return -0.5 * n * (math.log(2 * math.pi * bn.nanstd(xs)) - 1)
10% - :
factor = math.log(2*math.pi)
def loglike(xs):
n = len(xs)
return -0.5 * n * (factor + math.log(bn.nanstd(xs)) - 1)
2
, bn.nanstd . std, _ = bn.func.nansum_selector(xs, axis=0) bn.nanstd func.nanstd_1d_float64_axisNone, dtype.
, , Python. , , , , Cython , Python , .