【发布时间】:2018-12-11 00:48:16
【问题描述】:
链接在这里:https://www.csie.ntu.edu.tw/~r01922136/slides/ffm.pdf(幻灯片 5-6)
给定以下矩阵:
X : n * d
W : d * k
是否有一种仅使用矩阵运算(例如,numpy、tensorflow)来计算 n x 1 矩阵的有效方法,其中第 j 个元素是:
编辑:
当前的尝试是这样,但显然它的空间效率不是很高,因为它需要存储大小为 n*d*d 的矩阵:
n = 1000
d = 256
k = 32
x = np.random.normal(size=[n,d])
w = np.random.normal(size=[d,k])
xxt = np.matmul(x.reshape([n,d,1]),x.reshape([n,1,d]))
wwt = np.matmul(w.reshape([1,d,k]),w.reshape([1,k,d]))
output = xxt*wwt
output = np.sum(output,(1,2))
【问题讨论】:
标签: numpy tensorflow matrix machine-learning matrix-multiplication