Search code examples
numpylogarithm

Is there a way to easily get the logarithm of a np.ndarray containing errors


If I have a np.array of values, Y, with a no.array of corresponding errors, Err, the error in the log scale will be

Err_{log} =  log(Y+Err) - log(Y) = log ((Y+Err)/Y)

While I can place this in my code, this isn't much readable. Is there a function that does that?


Solution

  • NumPy has the function log1p(x) that computes the log of 1+x. So you could write:

    Err_log = np.log1p(Err/Y)