当我使用keras后端函数sqrt()时,我感到很困惑,.There是我的代码:
import numpy as np
from keras import backend as K
np.random.seed(1)
a = np.random.randint(low=0,high=50,size=(4,3))
b = np.random.randint(low=0,high=50,size=(4,3))
a = K.variable(value=a)
b = K.variable(value=b)
prod = K.sum(K.batch_dot(a,b))
sqrt = K.sqrt(K.batch_dot(a,b))`当我打印(Prod)时,输出为<tf.Tensor: shape=(), dtype=float32, numpy=4491.0>;当我打印( sqrt )时,输出为<tf.Tensor 'Sqrt_2:0' shape=(4, 1) dtype=float32>;我想知道为什么sqrt的输出没有result的值(无**numpy= ** ),以及如何获取该值?
有人能帮帮我吗?
发布于 2020-04-23 10:27:06
因为它返回一个张量。要获取一个值,您需要使用eval
K.eval(sqrt)发布于 2020-09-01 02:34:24
简单地说,您可以从后端获取函数
k.backend.sqrthttps://stackoverflow.com/questions/61378217
复制相似问题