title: How do you create a boolean mask for a tensor in Keras?
body: <p>I am building a custom metric to measure the accuracy of one class in my multi-class dataset during training. I am having trouble selecting the class. </p>
  
  <p>The targets are one hot (e.g: the class <code>0</code> label is <code>[1 0 0 0 0]</code>):</p>
  
  <pre><code>from keras import backend as K
  
  def single_class_accuracy(y_true, y_pred):
      idx = bool(y_true[:, 0])              # boolean mask for class 0 
      class_preds = y_pred[idx]
      class_true = y_true[idx]
      class_acc = K.mean(K.equal(K.argmax(class_true, axis=-1), K.argmax(class_preds, axis=-1)))  # multi-class accuracy  
      return class_acc
  </code></pre>
  
  <p>The trouble is, we have to use Keras functions to index tensors. How do you create a boolean mask for a tensor?</p>