Why tf.Variable is iterable but can't be iterated

Pekka

Why this is true:

from collections import Iterable
import tensorflow as tf

v = tf.Variable(1.0)
print(isinstance(v, Iterable))

True

while this

iter(v)

gives

TypeError: 'Variable' object is not iterable.
Ali Ismayilov

I found below method in Tensorflow's Variable class:

def __iter__(self):
    """Dummy method to prevent iteration. Do not call.
    NOTE(mrry): If we register __getitem__ as an overloaded operator,
    Python will valiantly attempt to iterate over the variable's Tensor from 0
    to infinity.  Declaring this method prevents this unintended behavior.
    Raises:
      TypeError: when invoked.
    """
    raise TypeError("'Variable' object is not iterable.")

https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/ops/variables.py#L366

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Dart, Why Iterable<T> can store in List<T> variable?

WSGI: Can the iterable returned from the app be iterated from different threads?

Can't apply gradients on tf.Variable

Why can't I cast an instance of a String to Iterable[Char] in Scala

Why aren't Enumerations Iterable?

Why can generator expressions be iterated over only once?

Why is the implicit cast of ArrayList<ArrayList<T>> to Iterable<Iterable<T>> impossible?

Why tf2 can't save a tf_function model as .pb file?

How an iterable object is iterated without next?

Why we use tf.Variable in tensorflow if we can directly use a variable without initialisation?

Why my variable is not iterable when i loop

A value of type 'List<int>' can't be assigned to a variable of type 'Iterable<int>'

Future builder flutter firebase error: A value of type 'Iterable<BlogPost>' can't be assigned to a variable of type 'List<BlogPost>'

A value of type 'Iterable<Food>' can't be assigned to a variable of type 'List<Food>'

How to fix error: A value of type Iterable can't be assigned to a variable of type 'List<dynamic>'?

Why does Stream<T> not implement Iterable<T>?

Why can't Python increment variable in closure?

Why can't pass my variable to applescript?

Why can't reset IFS variable?

Why can't a "Class" variable be passed to instanceof?

Why i can't use Variable in TRecord?

Why can't the console find my variable?

Why can't vue find variable in loop?

Why can't a variable be moved out of a closure?

Why can't I access this global variable?

Why can't my code access this variable?

Why method can't access class variable?

Why i can't take address of variable?

Why props variable can't be desctructed?