title: why does this error happens:"Sliced assignment is only supported for variables"
body: <p>I have a deep network using Keras and I need to apply cropping on the output of one layer and then send to the next layer. for this aim, I write the following code as a lambda layer:</p>
  
  <pre><code>def cropping_fillzero(img, rate=0.6): # Q = percentage
      residual_shape = img.get_shape().as_list()
      h, w = residual_shape[1:3]
      blacked_pixels = int((rate) * (h*w))
      ratio = int(np.floor(np.sqrt(blacked_pixels)))
  #    width = int(np.ceil(np.sqrt(blacked_pixels)))
  
      x = np.random.randint(0, w - ratio)
      y = np.random.randint(0, h - ratio)
      cropingImg = img[y:y+ratio, x:x+ratio].assign(tf.zeros([ratio, ratio]))
  
      return cropingImg
  
  decoded_noise = layers.Lambda(cropping_fillzero, arguments={'rate':residual_cropRate}, name='residual_cropout_attack')(bncv11)
  </code></pre>
  
  <p>but it produces the following error and I do not know why?!</p>
  
  <blockquote>
    <p>Traceback (most recent call last):</p>
    
    <p>File "", line 1, in 
        runfile('E:/code_v28-7-19/CIFAR_los4x4convolvedw_5_cropAttack_RandomSize_Pad.py',
    wdir='E:/code_v28-7-19')</p>
    
    <p>File
    "D:\software\Anaconda3\envs\py36\lib\site-packages\spyder_kernels\customize\spydercustomize.py",
    line 704, in runfile
        execfile(filename, namespace)</p>
    
    <p>File
    "D:\software\Anaconda3\envs\py36\lib\site-packages\spyder_kernels\customize\spydercustomize.py",
    line 108, in execfile
        exec(compile(f.read(), filename, 'exec'), namespace)</p>
    
    <p>File
    "E:/code_v28-7-19/CIFAR_los4x4convolvedw_5_cropAttack_RandomSize_Pad.py",
    line 143, in 
        decoded_noise = layers.Lambda(cropping_fillzero, arguments={'rate':residual_cropRate},
    name='residual_cropout_attack')(bncv11)</p>
    
    <p>File
    "D:\software\Anaconda3\envs\py36\lib\site-packages\keras\engine\base_layer.py",
    line 457, in <strong>call</strong>
        output = self.call(inputs, **kwargs)</p>
    
    <p>File
    "D:\software\Anaconda3\envs\py36\lib\site-packages\keras\layers\core.py",
    line 687, in call
        return self.function(inputs, **arguments)</p>
    
    <p>File
    "E:/code_v28-7-19/CIFAR_los4x4convolvedw_5_cropAttack_RandomSize_Pad.py",
    line 48, in cropping_fillzero
        cropingImg = img[y:y+ratio, x:x+ratio].assign(tf.zeros([ratio, ratio]))</p>
    
    <p>File
    "D:\software\Anaconda3\envs\py36\lib\site-packages\tensorflow\python\ops\array_ops.py",
    line 700, in assign
        raise ValueError("Sliced assignment is only supported for variables")</p>
    
    <p>ValueError: Sliced assignment is only supported for variables</p>
  </blockquote>
  
  <p>could you please tell me how can I solve this error?
  Thank you</p>