Understanding numpy.random.lognormal

Viewed 1670

I'm translating Matlab code (written by someone else) to Python.

In one section of the Matlab code, a variable X_new is set to a value drawn from a log-normal distribution as follows:

% log normal distribution
X_new = exp(normrnd(log(X_old), sigma));

That is, a random value is drawn from a normal distribution centered at log(X_old), and X_new is set to e raised to this value.

The direct translation of this code to Python is as follows:

import numpy as np


X_new = np.exp(np.random.normal(np.log(X_old), sigma))

But numpy includes a log-normal distribution which can be sampled directly.

My question is, is the line of code that follows equivalent to the lines of code above?

X_new = np.random.lognormal(np.log(X_old), sigma)
1 Answers
Related