title: TypeError: 'Tensor' object cannot be interpreted as an integer, tensorflow scan
body: <pre class="lang-py prettyprint-override"><code>import tensorflow as tf
  from tensorflow.keras.layers import Input
  max_seq_len=25
  input_mask = Input(max_seq_len,)
  input_mask = tf.scan(lambda _, x: tf.tensor_scatter_nd_update(x, [[0], [(tf.reduce_sum(x)) - 1]], [0, 0]), input_mask, initializer=tf.zeros(max_seq_len, dtype=tf.int64))
  
  Traceback (most recent call last):
    File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
    File &quot;/usr/local/anaconda3/envs/tfx/lib/python3.7/site-packages/tensorflow/python/util/dispatch.py&quot;, line 201, in wrapper
      return target(*args, **kwargs)
    File &quot;/usr/local/anaconda3/envs/tfx/lib/python3.7/site-packages/tensorflow/python/util/deprecation.py&quot;, line 574, in new_func
      return func(*args, **kwargs)
    File &quot;/usr/local/anaconda3/envs/tfx/lib/python3.7/site-packages/tensorflow/python/ops/functional_ops.py&quot;, line 816, in scan_v2
      name=name)
    File &quot;/usr/local/anaconda3/envs/tfx/lib/python3.7/site-packages/tensorflow/python/util/dispatch.py&quot;, line 201, in wrapper
      return target(*args, **kwargs)
    File &quot;/usr/local/anaconda3/envs/tfx/lib/python3.7/site-packages/tensorflow/python/ops/functional_ops.py&quot;, line 599, in scan
      infer_shape=True) for elem in elems_flat
    File &quot;/usr/local/anaconda3/envs/tfx/lib/python3.7/site-packages/tensorflow/python/ops/functional_ops.py&quot;, line 599, in &lt;listcomp&gt;
      infer_shape=True) for elem in elems_flat
    File &quot;/usr/local/anaconda3/envs/tfx/lib/python3.7/site-packages/tensorflow/python/ops/tensor_array_ops.py&quot;, line 1082, in __init__
      name=name)
    File &quot;/usr/local/anaconda3/envs/tfx/lib/python3.7/site-packages/tensorflow/python/ops/tensor_array_ops.py&quot;, line 718, in __init__
      self._tensor_array = [None for _ in range(size)]
  TypeError: 'Tensor' object cannot be interpreted as an integer
  
  </code></pre>
  <p>tensorflow version: 2.3.1
  keras version: 2.6.0</p>
  <p>the function of this code is to set the first and the last '1' in input_mask vector to 0.</p>
  <p>this code works when the input_mask = np.array([[1,1,1,1], [1,1,1,0]]),
  tf.scan cannot support tensor with the first dimension is unknown ?</p>
  <p>anyone knows how to implement the function or to fix this error? thanks</p>