将数据投影到较低维度上的后果

时间:2018-11-23 23:44:10

标签: python matplotlib

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
import math

na = 400

ma = [2, 1]

Sa = [[3, -2], [-2, 3]]

sigma1 = [3, 3]

nb = 400

mb = [8, 6]

Sb = [[3, -2], [-2, 3]]

xa, ya = np.random.multivariate_normal(ma, Sa, na).T

xb, yb = np.random.multivariate_normal(mb, Sb, nb).T

plt.plot(xa, ya, 'x')    
plt.plot(xb, yb, 'x')    
plt.axis('equal')    
plt.show()

我从二维高斯分布中随机生成数据,需要将其投影到w=[0, 1]上并绘制直方图。我尝试使用plt.hist,但不允许乘法。

1 个答案:

答案 0 :(得分:0)

下面的链接对于学习numpy可能很有用。

https://docs.scipy.org/doc/numpy-1.15.0/user/basics.creation.html https://jakevdp.github.io/PythonDataScienceHandbook/02.02-the-basics-of-numpy-arrays.html

我认为您的要求如下:

w = np.array([2,1])
a = np.array([xa,ya]).T
b = np.array([xb,yb]).T

aw = np.dot(a,w)
bw = np.dot(b,w)

plt.figure(0)
plt.hist(aw,label='a',histtype='step')
plt.hist(bw,label='b',histtype='step')
plt.title('projected')
plt.legend()