title: Data API Error : Cannot convert a symbolic Tensor (truediv:0) to a numpy array
body: <p>I have 45000 images of size 224*224, stored as a numpy array. This array, called <code>source_arr</code> has shape 45000,224,224 and it fits in the memory.</p>
  <p>I want to divide this array into train, test and validate array and pre-process (normalize and convert greyscale to 3 channels RGB) them using tf.data API.</p>
  <p>I have written a pre process function like:</p>
  <pre><code>def pre_process(x):
       #Zero centering the scaled dataset
       x_norm = (x-mean_Rot_MIP)/Var_Rot_MIP
       #Stack 3 channels
       x_norm_3ch= np.stack((x_norm, x_norm, x_norm),axis=0)
       print('Rotn MIP 3ch dim:', x_norm_3ch.shape) # (3, 224, 224)
       #converting  channel 1st to channel last move axis 1 to 3
       x_norm_3ch = moveaxis(x_norm_3ch, 0,2) 
       print('Rotn MIP ch last dim: ',x_norm_3ch.shape)  # (224, 224, 3)   
       return x_norm_3ch
  </code></pre>
  <p><code>X_train_cases_idx.idx</code> contains the index of images from source_arr that are part of training data.</p>
  <p>I have read the corresponding training images from <code>source_arr</code> in the dataset object like:</p>
  <pre><code>X_train = tf.data.Dataset.from_tensor_slices([source_arr[i] for i in X_train_cases_idx.idx])
  </code></pre>
  <p>And then I apply the <code>pre_process</code> function on the training images like
  <code>X_train = X_train.map(pre_process)</code></p>
  <p>but I get the following error</p>
  <pre><code>Traceback (most recent call last):
  
    File &quot;&lt;ipython-input-37-69aa131a6944&gt;&quot;, line 1, in &lt;module&gt;
      X_train = X_train.map(pre_process)
  
    File &quot;C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\data\ops\dataset_ops.py&quot;, line 1695, in map
      return MapDataset(self, map_func, preserve_cardinality=True)
  
    File &quot;C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\data\ops\dataset_ops.py&quot;, line 4045, in __init__
      use_legacy_function=use_legacy_function)
  
    File &quot;C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\data\ops\dataset_ops.py&quot;, line 3371, in __init__
      self._function = wrapper_fn.get_concrete_function()
  
    File &quot;C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\eager\function.py&quot;, line 2939, in get_concrete_function
      *args, **kwargs)
  
    File &quot;C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\eager\function.py&quot;, line 2906, in _get_concrete_function_garbage_collected
      graph_function, args, kwargs = self._maybe_define_function(args, kwargs)
  
    File &quot;C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\eager\function.py&quot;, line 3213, in _maybe_define_function
      graph_function = self._create_graph_function(args, kwargs)
  
    File &quot;C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\eager\function.py&quot;, line 3075, in _create_graph_function
      capture_by_value=self._capture_by_value),
  
    File &quot;C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\framework\func_graph.py&quot;, line 986, in func_graph_from_py_func
      func_outputs = python_func(*func_args, **func_kwargs)
  
    File &quot;C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\data\ops\dataset_ops.py&quot;, line 3364, in wrapper_fn
      ret = _wrapper_helper(*args)
  
    File &quot;C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\data\ops\dataset_ops.py&quot;, line 3299, in _wrapper_helper
      ret = autograph.tf_convert(func, ag_ctx)(*nested_args)
  
    File &quot;C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\autograph\impl\api.py&quot;, line 258, in wrapper
      raise e.ag_error_metadata.to_exception(e)
  
  NotImplementedError: in user code:
  
      &lt;ipython-input-2-746b4230fbd1&gt;:58 pre_process  *
          x_norm_3ch= np.stack((x_norm, x_norm, x_norm),axis=1)
      &lt;__array_function__ internals&gt;:6 stack  **
          
      C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\shape_base.py:419 stack
          arrays = [asanyarray(arr) for arr in arrays]
      C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\shape_base.py:419 &lt;listcomp&gt;
          arrays = [asanyarray(arr) for arr in arrays]
      C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\_asarray.py:138 asanyarray
          return array(a, dtype, copy=False, order=order, subok=True)
      C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py:848 __array__
          &quot; a NumPy call, which is not supported&quot;.format(self.name))
  
      NotImplementedError: Cannot convert a symbolic Tensor (truediv:0) to a numpy array. This error may indicate that you're trying to pass a Tensor to a NumPy call, which is not supported
  </code></pre>
  <p>What am I doing wrong, and how do I fix it?
  I am using Tensorflow 2.0 with python 3.7 on windows 10</p>