gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 21:32:22 24 4
gpt4 key购买 nike

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 但它不允许乘法。

最佳答案

以下链接可能对学习 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()

关于python - 将数据投影到较低维度的后果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53453957/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com