Reputation: 143
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')
This line gives me the error
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]
Upvotes: 5
Views: 4894
Reputation: 143
addn = tf.add(mul, tf.cast(div, tf.int32))
This helped
tf.cast(
x,
dtype,
name=None
)
Sorry for asking a question if that was stupid !!!
Upvotes: 7