I need to change the value of some elements of a tensor. I know what elements -- they are in a boolean tensor already.
I don't see how to do this in keras code. But if I were using TensorFlow code I would do something like this:
Conditional assignment of tensor values in TensorFlow
In python numpy, the code would look something like this:
x = np.zeros_like(sometensor)
x[sometensor>0.5] = 1.0
In Keras code (and I'm using TF backend) here's my best attempt (does not work):
encoder_outputs_bin = k.backend.zeros_like(encoder_outputs, name="encoder_outputs_bin")
point_five = k.backend.constant(0.5, shape=k.backend.shape(encoder_outputs), name="point_five")
positives = k.backend.greater_equal(encoder_outputs, point_five)
encoder_outputs_bin[positives].assign(tf.ones(1)) # TF syntax -- might not work in keras