gpt4 book ai didi

python - 无法计算 Add as input #1(zero-based) 预计是一个 int32 张量,但它是一个双张量 [Op :Add]

转载 作者:行者123 更新时间:2023-12-04 01:34:49 25 4
gpt4 key购买 nike

import tensorflow as tf
a = tf.constant(6, name = 'constant_a')
b = tf.constant(3, name = 'constant_b')
c = tf.constant(10, name = 'constant_c')
d = tf.constant(5, name = 'constant_d')
mul = tf.multiply(a, b, name = 'mul')
div = tf.divide(c, d, name = 'div')

这一行给了我错误
addn = tf.add(mul, div)
InvalidArgumentError                      Traceback (most recent call last)
<ipython-input-8-387060d1ddd5> in <module>()
----> 1 addn = tf.add(mul, div)

~/.local/lib/python3.5/site-packages/tensorflow_core/python/ops/gen_math_ops.py in add(x, y, name)
341 raise
342 except _core._NotOkStatusException as e:
--> 343 _ops.raise_from_not_ok_status(e, name)
344 # Add nodes to the TensorFlow graph.
345 try:

~/.local/lib/python3.5/site-packages/tensorflow_core/python/framework/ops.py in raise_from_not_ok_status(e, name)
6604 message = e.message + (" name: " + name if name is not None else "")
6605 # pylint: disable=protected-access
-> 6606 six.raise_from(core._status_to_exception(e.code, message), None)
6607 # pylint: enable=protected-access
6608

~/.local/lib/python3.5/site-packages/six.py in raise_from(value, from_value)

InvalidArgumentError: cannot compute Add as input #1(zero-based) was expected to be a int32 tensor but is a double tensor [Op:Add]

最佳答案

addn = tf.add(mul, tf.cast(div, tf.int32))

这有助于
 tf.cast(
x,
dtype,
name=None
)

抱歉问了一个问题,如果那是愚蠢的!!!

关于python - 无法计算 Add as input #1(zero-based) 预计是一个 int32 张量,但它是一个双张量 [Op :Add],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59938419/

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