title: Writing a custom loss function element by element for Keras
body: <p>I am new to machine learning, python and tensorflow. I am used to code in C++ or C# and it is difficult for me to use tf.backend.
  I am trying to write a custom loss function for an LSTM network that tries to predict if the next element of a time series will be positive or negative. My code runs nicely with the binary_crossentropy loss function. I want now to improve my network having a loss function that adds the value of the next time series element if the predicted probability is greater than 0.5 and substracts it if the prob is less or equal to 0.5.
  I tried something like this:</p>
  
  <pre><code>def customLossFunction(y_true, y_pred):
      temp = 0.0
      for i in range(0, len(y_true)):
          if(y_pred[i] &gt; 0):
              temp += y_true[i]
          else:
              temp -= y_true[i]
      return temp
  </code></pre>
  
  <p>Obviously, dimensions are wrong but since I cannot step into my function while debugging, it is very hard to get a grasp of dimensions here.
  Can you please tell me if I can use an element-by-element function? If yes, how? And if not, could you help me with tf.backend?
  Thanks a lot</p>