python - 类型错误 : 'DType' object is not callable

标签 python tensorflow

以下代码抛出一个TypeError

import tensorflow as tf
h=tf.int32(6)

错误:

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

为什么?

最佳答案

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

h = tf.constant(6, dtype=tf.int32)

关于python - 类型错误 : 'DType' object is not callable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48043359/

相关文章:

python - 如何将 @tf.function 与 Keras 顺序 API 一起使用?

tensorflow 图大小

python - 如何在 Tensorflow 中高效加入 TFRecords 中的数据

python - 在 Python 中,使用二分法在字典列表中查找项目

python - 在 Python 2 的异常中处理错误?

python - 为什么 if block 在 else 之后执行?

python - 用列表切片张量 - TensorFlow

python - xml.etree.ElementTree.Element.remove 的项目和列表(项目)中的 x 之间的差异

python - numpy 矩阵乘法的奇怪性能结果

python - 运行 Tf.Keras 模型时内存不足