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

gives error instead of giving 'false'

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

Why does this produce an error. I'm using tensorflow 0.8 Shouldn't one be able to check equality b/w any variables.

What I was trying to achieve was checking if an object is present in a list

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

1 Answer 1

4

This comparison does not make sense.

>>> a=tf.int32
>>> type(a)
<class 'tensorflow.python.framework.dtypes.DType'>
>>> print(a)
<dtype: 'int32'>

versus

>>> b=tf.constant(3)
>>> type(b)
<class 'tensorflow.python.framework.ops.Tensor'>
>>> print(b)
Tensor("Const_1:0", shape=(), dtype=int32)

What you see here, is that you are trying to compare a type (or class) with some form of instance of that class. There's no point in actually doing this. The error is thrown because tf has no idea how to actually perform this equality check.

Update

I see you updated your answer, so here the response: While this is the correct syntax to check if an object is in a collection, my answer above still applies. The variable a does not refer to what you think it does. It holds a reference to the actual definition of the type int32. There is no point of looking for that in a tensor.

3
  • I was trying to check if an object is present in a list. (for i in list) if i is tf.int32 and list contains tf.constant(3) I am getting an error due to this equality check. Any idea how i can accomplish this Jul 15, 2016 at 14:29
  • Since that might help other people, I'd suggest you open a new question for your actual issue. You can add a comment here so I can find the new question. If this answer helped you, please consider accepting it.
    – Dave
    Jul 15, 2016 at 14:31
  • I really need to check if that object is present in that list. so I iterated and check if item 'is' tf.int32 instead of == Jul 15, 2016 at 14:53

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.