给定一个点(x,y)我将如何创建n个随机点,它们与(x,y)的距离是用sigma和mean表示的高斯分布作为参数?Python在点附近添加高斯噪声
0
A
回答
2
您必须使用多变量正态分布。对于你的情况,你必须在X轴和Y轴上使用正态分布。如果你绘制分布图,它将是一个三维钟形曲线。
使用numpy的多元正态分布。
numpy.random.multivariate_normal(mean, cov[, size])
mean : 1-D array_like, of length N
Mean of the N-dimensional distribution.
cov : 2-D array_like, of shape (N, N)
Covariance matrix of the distribution. It must be symmetric and positive-semidefinite for proper sampling.
size : int or tuple of ints, optional
Given a shape of, for example, (m,n,k), m*n*k samples are generated, and packed in an m-by-n-by-k arrangement. Because each sample is N-dimensional, the output shape is (m,n,k,N). If no shape is specified, a single (N-D) sample is returned.
Returns:
out : ndarray
The drawn samples, of shape size, if that was provided. If not, the shape is (N,).
In other words, each entry out[i,j,...,:] is an N-dimensional value drawn from the distribution.
0
您可以使用numpy.random.normal
从高斯分布的新的X和Y坐标拉随机数。
from numpy.random import normal
sigma = 1.0
point_0 = (0.0, 0.0)
point_1 = [i + normal(0, sigma) for i in point]
这在这种情况下起作用,因为在x和y维度上乘以高斯分布将给出径向维度的高斯分布。 I.E. exp(-r^2/a^2) = exp(-x^2/a^2) * exp(-y^2/a^2)
6
对于2-D分配使用numpy.random.normal
。诀窍是你需要获得每个维度的分布。因此,例如周边的点(4,4)的随机分布,西格马0.1:
sample_x = np.random.normal(4, 0.1, 500)
sample_y = np.random.normal(4, 0.1, 500)
fig, ax = plt.subplots()
ax.plot(sample_x, sample_y, '.')
fig.show()
可以完成同样的事情numpy.random.multivariate_normal
如下:
mean = np.array([4,4])
sigma = np.array([0.1,0.1])
covariance = np.diag(sigma ** 2)
x, y = np.random.multivariate_normal(mean, covariance, 1000)
fig, ax = plt.subplots()
ax.plot(x, y, '.')
对于你可以使用scipy.stats.multivariate_normal
这样的3-D分布:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
from scipy.stats import multivariate_normal
x, y = np.mgrid[3:5:100j, 3:5:100j]
xy = np.column_stack([x.flat, y.flat])
mu = np.array([4.0, 4.0])
sigma = np.array([0.1, 0.1])
covariance = np.diag(sigma ** 2)
z = multivariate_normal.pdf(xy, mean=mu, cov=covariance)
z = z.reshape(x.shape)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x, y, z)
fig.show()
相关问题
- 1. 高斯噪声vs高斯白噪声
- 2. 使用matlab添加高斯白噪声
- 3. 用C++添加高斯噪声
- 4. 如何添加泊松噪声和高斯噪声?
- 5. OpenCV - 高斯噪声
- 6. 高斯噪声,MATLAB
- 7. Octave/Matlab - 高斯噪声
- 8. emgucv中的高斯噪声
- 9. 显示高斯噪声
- 10. Tensorflow中的加性高斯噪声
- 11. 模拟高斯噪声数据的Python高斯拟合
- 12. 向所有张量变量添加高斯噪声
- 13. 添加具有高斯分布的泊松噪声
- 14. 用高斯噪声绘制线
- 15. 哪一个是模拟附加高斯噪声的正确方法
- 16. Python的 - 适合于高斯噪声数据与lmfit
- 17. 向图像添加噪声
- 18. 应用于图像的高斯噪声(用于模拟传感器噪声)
- 19. 增加噪声的信号在python
- 20. 在opencv中将高斯噪声转换为emgu cv
- 21. 将泊松噪声添加到图像
- 22. 将RMS噪声添加到图像
- 23. 高斯噪声对图像直方图有什么影响?
- 24. MATLAB:是什么使用imnoise和randn为高斯噪声
- 25. 使用过滤器2去除高斯噪声
- 26. 如何从MATLAB中的图像中去除高斯噪声?
- 27. 如何使用python将噪声添加到wav文件?
- 28. 在行按钮附近添加UIView?
- 29. PIL - 在.png附近添加透明度
- 30. 如何通过div将高度添加到附近?
你想要[this](https://i.stack.imgur.com/eu7Jc.png)之类的东西吗? – manelfp
@ManelFornos是的! –