【Python】Error:Input 'y' of 'Add' Op has type float32 that does not match type int32 of argument 'x'.
生活随笔
收集整理的這篇文章主要介紹了
【Python】Error:Input 'y' of 'Add' Op has type float32 that does not match type int32 of argument 'x'.
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
學(xué)習(xí)Python,碰到數(shù)據(jù)類型不一致進(jìn)行運(yùn)算出現(xiàn)的問題,問題現(xiàn)象、原因、解決辦法如下。
1、問題代碼
# 引入 tensorflow 模塊 import tensorflow as tf# 創(chuàng)建兩個(gè)常量節(jié)點(diǎn) node1 = tf.constant([2,5], dtype=tf.int32) node2 = tf.constant([1,2], dtype=tf.float32)#創(chuàng)建add節(jié)點(diǎn),實(shí)現(xiàn)上面2個(gè)節(jié)點(diǎn)的加操作 adder = node1 + node2#打印3個(gè)節(jié)點(diǎn) print(node1) print(node2) print(adder)# 打印 adder 運(yùn)行后的結(jié)果 sess = tf.Session() print(sess.run(adder))問題現(xiàn)象:
2、問題原因
node1數(shù)據(jù)類型是int,但node2數(shù)據(jù)類型是float
3、解決辦法
# 引入 tensorflow 模塊 import tensorflow as tf# 創(chuàng)建兩個(gè)常量節(jié)點(diǎn) node1 = tf.constant([2,5], dtype=tf.float32) node2 = tf.constant([1,2], dtype=tf.float32)#創(chuàng)建add節(jié)點(diǎn),實(shí)現(xiàn)上面2個(gè)節(jié)點(diǎn)的加操作 adder = node1 + node2#打印3個(gè)節(jié)點(diǎn) print(node1) print(node2) print(adder)# 打印 adder 運(yùn)行后的結(jié)果 sess = tf.Session() print(sess.run(adder))正確運(yùn)行結(jié)果:
總結(jié)
以上是生活随笔為你收集整理的【Python】Error:Input 'y' of 'Add' Op has type float32 that does not match type int32 of argument 'x'.的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: VS2013+opencv2.4.9配置
- 下一篇: Tensorflow初学者之搭建神经网络