【发布时间】:2019-05-09 19:37:31
【问题描述】:
我刚刚开始学习 TensorFlow。引用自documentation:
让我们构建一个简单的计算图。最基本的操作是常数。构建操作的 Python 函数将张量值作为输入。结果操作不接受任何输入。运行时,它输出传递给构造函数的值。我们可以创建两个浮点常量 a 和 b,如下所示:
a = tf.constant(3.0, dtype=tf.float32)
b = tf.constant(4.0) # also tf.float32 implicitly
total = a + b
print(a)
print(b)
print(total)
第二个常量被隐式类型为 float32。这是基于第一个常量的显式类型吗?这是否意味着第一个 dtype 是必需的? tf.constant documentation 暗示它没有:
如果未指定参数 dtype,则从
value的类型推断类型。
但是没有必要显式键入上面的 3.0 常量。
我只是想对此进行澄清,因为就像我说的那样,我才刚刚开始。
【问题讨论】:
标签: python tensorflow types