gpt4 book ai didi

python - Keras 中的矩阵乘法

转载 作者:太空狗 更新时间:2023-10-29 21:20:38 25 4
gpt4 key购买 nike

我尝试使用 Keras 在 python 程序中将两个矩阵相乘。

import keras.backend as K
import numpy as np
A = np.random.rand(10,500)
B = np.random.rand(500,6000)

x = K.placeholder(shape=A.shape)
y = K.placeholder(shape=B.shape)
xy = K.dot(x, y)

xy.eval(A,B)

我知道这行不通,但我也不知道如何让它发挥作用。

最佳答案

您需要使用变量而不是占位符。

import keras.backend as K
import numpy as np
A = np.random.rand(10,500)
B = np.random.rand(500,6000)

x = K.variable(value=A)
y = K.variable(value=B)

z = K.dot(x,y)

# Here you need to use K.eval() instead of z.eval() because this uses the backend session
K.eval(z)

关于python - Keras 中的矩阵乘法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43871575/

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