Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate n-dimensional random numbers in Python

I'm trying to generate random numbers from a gaussian distribution. Python has the very useful random.gauss() method, but this is only a one-dimensional random variable. How could I programmatically generate random numbers from this distribution in n-dimensions?

For example, in two dimensions, the return value of this method is essentially distance from the mean, so I would still need (x,y) coordinates to determine an actual data point. I suppose I could generate two more random numbers, but I'm not sure how to set up the constraints.

I appreciate any insights. Thanks!

like image 879
Magsol Avatar asked Nov 25 '25 21:11

Magsol


1 Answers

Numpy has multidimensional equivalents to the functions in the random module

The function you're looking for is numpy.random.normal

like image 83
Andrew Walker Avatar answered Nov 28 '25 11:11

Andrew Walker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!