title: Keras backend function that gives one only if values are between a and b
body: <p>I am trying to write a Keras backend function that if the input x is between a and b, it gives 1; otherwise, it gives zero. I was not able to do this using the functions available in Keras backend.  If it was numpy, I would write:</p>
  
  <pre><code>def my_function(x):
      import numpy as np
      y=np.int64(np.logical_and(x&gt;=a, x&lt;=b))
      return y
  </code></pre>
  
  <p><strong>Question 1:</strong> How can I do this using Keras backend? I know I can use something like this, but it is not efficient</p>
  
  <pre><code>def my_function(x):
      from keras import backend as K
      y=x
      for i in y:
          if i&lt;=b and i&gt;=a:
              i=1
          else:
              i=0
   return y
  </code></pre>
  
  <p><strong>Question 2:</strong> I have installed TensorFlow 1.14.0 and Keras 2.2.6 so I think the backend is Tensorflow. If I cannot do it in Keras backend. How can I write my function in the TensorFlow backend? </p>