当我使用dtype=tf.32浮动
import tensorflow as tf
z = tf.Variable(tf.ones(5, dtype=tf.float32), name='z')
init = tf.global_variables_initializer()
with tf.Session() as session:
session.run(init)
print("z=" , session.run(z))
for i in range(5):
z = z +1
print(session.run(z))
结果是这样的:
('z=', array([0., 0., 0., 0., 0.], dtype=float32))
[0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0.]
但是,当我使用数据类型=tf.int32型
z = tf.Variable(tf.ones(5, dtype=tf.int32), name='z')
结果是:
('z=', array([1, 1, 1, 1, 1], dtype=int32))
[2 2 2 2 2]
[3 3 3 3 3]
[4 4 4 4 4]
[5 5 5 5 5]
[6 6 6 6 6]
你能帮我解释一下为什么使用tf.32浮动?你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐