title: Iterating over tf.Tensor is not allowed: AutoGraph is disabled in this function
body: <p>I am using tensorflow 2.1 along with python 3.7</p>
  
  <p>The following snippet of code is being used to build a tensorflow graph. The code runs without errors when executed as a standalone python script. (Probably tensorflow is running in eager mode? I am not sure.)  </p>
  
  <pre><code>import tensorflow as tf
  patches = tf.random.uniform(shape=(1, 10, 50, 300), dtype=tf.dtypes.float32)
  s = tf.shape(patches)
  patches = [patches[0][x][y] - tf.reduce_mean(patches[0][x][y]) for y in tf.range(s[2]) for x in tf.range(s[1])]
  </code></pre>
  
  <p>However, the code fails when this is part of a tensorflow graph. I receive the following error:
  tensorflow.</p>
  
  <blockquote>
    <p>python.framework.errors_impl.OperatorNotAllowedInGraphError: iterating
    over <code>tf.Tensor</code> is not allowed: AutoGraph is disabled in this function. Try decorating it directly with @tf.function.</p>
  </blockquote>
  
  <p>I also added the decorator <code>@tf.function</code> to the method which wraps the above lines of code. It didn't help. I am not sure if I fully understand the meaning of decorating with <code>@tf.function</code>. I also checked that this could be a problem with using python list comprehension inside the tensorflow graph. I am not sure how to use <a href="https://www.tensorflow.org/api_docs/python/tf/map_fn" rel="noreferrer">tf.map_fn</a> or <a href="https://www.tensorflow.org/api_docs/python/tf/while_loop" rel="noreferrer">tf.while_loop</a> for my case, since I have nested loops. </p>
  
  <p>Thanks in advance!</p>