Python: how to randomly sample from nonstandard Cauchy distribution, hence with different parameters? Python: how to randomly sample from nonstandard Cauchy distribution, hence with different parameters? numpy numpy

Python: how to randomly sample from nonstandard Cauchy distribution, hence with different parameters?


If you have scipy, you can use scipy.stats.cauchy, which takes a location (x0) and a scale (gamma) parameter. It exposes the rvs method to draw random samples:

x = stats.cauchy.rvs(loc=100, scale=2.5, size=1000)  # draw 1000 samples


You may avoid the dependency on SciPy, since the Cauchy distribution is part of the location-scale family. That means, if you draw a sample x from Cauchy(0, 1), just shift it by x_0 and multiply with gamma and x' = x_0 + gamma * x will be distributed according to Cauchy(x_0, gamma).