Search code examples
pythonnumpyscipystatisticsdistribution

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


I was looking here: numpy

And I can see you can use the command np.random.standard_cauchy() specifying an array, to sample from a standard Cauchy.

I need to sample from a Cauchy which might have x_0 != 0 and gamma != 1, i.e. might not be located at the origin, nor have scale equal to 1.

How can I do this?


Solution

  • 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