#python #python-2.7 #tensorflow #iterable
#python #python-2.7 #тензорный поток #итеративный
Вопрос:
Почему это так:
from collections import Iterable
import tensorflow as tf
v = tf.Variable(1.0)
print(isinstance(v, Iterable))
True
в то время как это
iter(v)
дает
TypeError: 'Variable' object is not iterable.
Ответ №1:
Я нашел метод ниже в классе переменных Tensorflow:
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