类型错误:“DType”对象不可调用

nav*_* kt 1 python tensorflow

以下代码抛出一个 TypeError

import tensorflow as tf
h=tf.int32(6)
Run Code Online (Sandbox Code Playgroud)

错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'DType' object is not callable
Run Code Online (Sandbox Code Playgroud)

为什么?

mrr*_*rry 5

tf.int32对象不是构造函数。如果要创建类型tf.int32为 value的张量6,则应使用tf.constant(),如下所示:

h = tf.constant(6, dtype=tf.int32)
Run Code Online (Sandbox Code Playgroud)