Python Tensorflow比较tf.int32和tf.constant会给出错误

Python Tensorflow比较tf.int32和tf.constant会给出错误,python,python-3.x,tensorflow,python-3.4,Python,Python 3.x,Tensorflow,Python 3.4,给出错误而不是“false” import tensorflow as tf a=tf.int32 b=tf.constant(3) a==b 这种比较毫无意义 a=tf.int32 b=[tf.constant(3),..other objects] if a in b: do_something() 对 >>> a=tf.int32 >>> type(a) <class 'tensorflow.python.framework.dtypes

给出错误而不是“false”

import tensorflow as tf
a=tf.int32 
b=tf.constant(3)
a==b

这种比较毫无意义

a=tf.int32
b=[tf.constant(3),..other objects]
if a in b:
  do_something()

>>> a=tf.int32
>>> type(a)
<class 'tensorflow.python.framework.dtypes.DType'>
>>> print(a)
<dtype: 'int32'>
您在这里看到的是,您试图将一个类型或类与该类的某种形式的实例进行比较。实际上这样做没有意义。抛出此错误是因为tf不知道如何实际执行此相等性检查

更新

我看到你更新了答案,所以回复如下:
虽然这是检查对象是否在集合中的正确语法,但我上面的回答仍然适用。变量a并不是指您认为它的作用。它包含对int32类型的实际定义的引用。在张量中寻找它是没有意义的

我试图检查列表中是否存在对象。对于列表中的i,如果i是tf.int32且列表包含tf.constant3,则由于此相等性检查,我将收到一个错误。如果你知道我怎样才能做到这一点,既然这可能会帮助其他人,我建议你为你的实际问题提出一个新问题。你可以在这里添加评论,这样我就可以找到新问题。如果这个答案帮助了你,请考虑接受它。我真的需要检查这个对象是否存在于该列表中。因此,我迭代并检查项“是否”是tf.int32,而不是==
>>> a=tf.int32
>>> type(a)
<class 'tensorflow.python.framework.dtypes.DType'>
>>> print(a)
<dtype: 'int32'>
>>> b=tf.constant(3)
>>> type(b)
<class 'tensorflow.python.framework.ops.Tensor'>
>>> print(b)
Tensor("Const_1:0", shape=(), dtype=int32)