2016-10-01 38 views

回答

4

我發現下面的方法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

相關問題