如何用Python生成2D高斯? [英] How to generate 2D gaussian with Python?

查看:198
本文介绍了如何用Python生成2D高斯?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用random.gauss(mu, sigma)函数生成高斯数据,但是如何生成2D高斯呢?有这样的功能吗?

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

推荐答案

由于标准2D高斯分布只是两个1D高斯分布的乘积,因此如果两个轴之间没有相关性(即协变矩阵是对角线),只需调用random.gauss两次即可.

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)

这篇关于如何用Python生成2D高斯?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆