2016-07-15 37 views
-3
import tensorflow as tf 
a=tf.int32 
b=tf.constant(3) 
a==b 

给出的而不是给 '假'Tensorflow比较tf.int32和tf.constant给出错误

Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/framework/dtypes.py", line 248, in __eq__ 
    and self._type_enum == as_dtype(other).as_datatype_enum) 
    File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/framework/dtypes.py", line 536, in as_dtype 
    if key == type_value: 
TypeError: data type not understood 

为什么这个产生错误的错误。我正在使用张量流0.8 不应该能够检查相等的b/w任何变量。

我是想实现在检查对象是否存在于列表

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

回答

4

这种比较是没有意义的。

>>> 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) 

你在这里看到的是什么,是你正在试图比较类型(或类)与某种形式的类的实例。实际做这件事没有意义。错误被抛出,因为tf不知道如何实际执行这种平等检查。

更新

我看到你更新你的答案,所以这里的响应: 虽然这是正确的语法检查的对象是一个集合中,我的回答上面仍然适用。变量a没有提到你认为它的作用。它包含对int32类型的实际定义的引用。在张量中寻找它没有意义。

+0

我试图检查一个对象是否出现在列表中。 (对于我在列表中)如果我是tf.int32和列表包含tf.constant(3)由于这种相等性检查,我得到一个错误。任何想法我可以如何完成这 – Himaprasoon

+0

因为这可能会帮助其他人,我建议你为你的实际问题开一个新的问题。你可以在这里添加评论,所以我可以找到新的问题。如果这个答案对你有帮助,请考虑接受它。 – Dave

+0

我真的需要检查该对象是否存在于该列表中。所以我迭代并检查项目'是'tf.int32而不是== – Himaprasoon