How to generate 2D gaussian with Python?

后端 未结 6 930
囚心锁ツ
囚心锁ツ 2020-12-24 06:42

I can generate Gaussian data with random.gauss(mu, sigma) function, but how can I generate 2D gaussian? Is there any function like that?

6条回答
  •  渐次进展
    2020-12-24 07:12

    Since the standard 2D Gaussian distribution is just the product of two 1D Gaussian distribution, if there are no correlation between the two axes (i.e. the covariant matrix is diagonal), just call random.gauss twice.

    def gauss_2d(mu, sigma):
        x = random.gauss(mu, sigma)
        y = random.gauss(mu, sigma)
        return (x, y)
    

提交回复
热议问题