給定一個點(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是的! –