Below code will show the difference between two.
t1 = tf.constant(value=1)
t1.dtype
Output
tf.int32
t2 = tf.constant(value=1.0)
t2.dtype
Output
tf.float32
now adding these two tensors will throw an error as data type for these two are different.
t3 = tf.add(x=t1, y=t2)
Output:
Traceback (most recent call last):
File "c:\ProgramData\Anaconda3\envs\tensorflow_cpu\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 527, in _apply_op_helper
preferred_dtype=default_dtype)
File "c:\ProgramData\Anaconda3\envs\tensorflow_cpu\lib\site-packages\tensorflow\python\framework\ops.py", line 1224, in internal_convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
File "c:\ProgramData\Anaconda3\envs\tensorflow_cpu\lib\site-packages\tensorflow\python\framework\ops.py", line 1018, in _TensorTensorConversionFunction
(dtype.name, t.dtype.name, str(t)))
ValueError: Tensor conversion requested dtype int32 for Tensor with dtype float32: 'Tensor("Const_4:0", shape=(), dtype=float32)'