我没有从下面的代码中得到 CNTK 所期望的正确答案。我做错了什么吗?
import cntk as C
import numpy as np
def custom(a, b, c):
return a * 0 + c * 0 + b
np.set_printoptions(edgeitems=1000, linewidth=1000)
a = C.input_variable(3)
b = C.input_variable(3)
c = C.input_variable(3)
f = custom(a, b, c)
q = np.zeros((1, 3)).astype(np.float32) + 0.5
w = np.zeros((1, 3)).astype(np.float32) + 1.0
e = np.zeros((1, 3)).astype(np.float32) + 1.5
print()
print("a:", q)
print("b:", w)
print("c:", e)
print(">>>>>>>>>>>>>>>>>>>>>")
results = f(q, w, e)
print(results)
我要求返回结果
[[1.0, 1.0, 1.0]]
但我得到了,
[[1.5, 1.5, 1.5]]
相反。 任何人都可以复制这个吗?复制和粘贴运行应该不会出现错误。
编辑:我意识到在函数中移动变量 b 的位置也会改变它的值。
最佳答案
您需要使用eval()
来获取变量的计算结果。
因此,将行 results = f(q, w, e)
替换为 results = f.eval({a: q, b: w, c: e})
将得到预期的结果。
关于python - 尝试在微软CNTK中制作一个极其简单的功能但得到错误的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46731358/