Having an array like this :
input = np.array([0.04, -0.8, -1.2, 1.3, 0.85, 0.09, -0.08, 0.2])
I want to change all the values between -0.1 and 0.1 to zero and change the rest to 1
filtred = [0, 1, 1, 1, 1, 0, 0, 1]
Using the lamnda
layer is not my favor choice (I would prefer to get find a solution with a native layer which could be easily converted to TfLite) but I tried anyway :
layer = tf.keras.layers.Lambda(lambda x: 0 if x <0.1 and x>-0.1 else x)
layer(input)
I am getting :
ValueError: Exception encountered when calling Lambda.call().
The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Arguments received by Lambda.call():
โข inputs=tf.Tensor(shape=(6,), dtype=float32)
โข mask=None
โข training=None