title: Function implementation in keras tensorflow
body: <p>Suppose I´ve got three tensors shape <code>(n,1) T,r,E</code> and I wanted to implement a function that calculates: <code>sum(i,j) (T[j] &lt; T[i]) (r[j] &gt; r[i]) E[j]</code>.
  How can I proceed?</p>
  
  <p>This is what I´ve got</p>
  
  <pre class="lang-py prettyprint-override"><code>#tensor examples
  T=K.constant([1,4,5])
  r=K.constant([.8,.3,.7])
  E=K.constant([1,0,1])
  
  # cartesian product of T to compare element wise
  c = tf.stack(tf.meshgrid(T, T, indexing='ij'), axis=-1)
  cartesian_T = tf.reshape(c, (-1, 2))
  
  # cartesian product of r to compare elemento wise
  r = tf.stack(tf.meshgrid(r, r, indexing='ij'), axis=-1)
  cartesian_r = tf.reshape(r, (-1, 2))
  
  # TO DO: 
  # compare the two columns in cartesian T and cast to integer 1/0 if  
  # second column in T less/greater than first column in T =&gt; return tensor
  
  
  # compare the two columns in cartesian E and cast to integer 1/0 if  
  # second column in r greater/less than first column in r =&gt; return tensor
  
  # multiply previous tensors by a broadcasted version of E, then do K.sum()
  </code></pre>
  
  <p>Do you think I'm on the right track? What would you suggest to implement this?</p>