Использование бэкэнда keras K.cast(K.equal(a, K.max(a)), dtype='int8')
import numpy as np
import tensorflow as tf
from tensorflow.keras import backend as K
a = np.arange(0, 1, 0.1)
a = a[:, np.newaxis]
a
array([[0. ],
[0.1],
[0.2],
[0.3],
[0.4],
[0.5],
[0.6],
[0.7],
[0.8],
[0.9]], dtype=float32)
tensor = K.cast(a, dtype='float32')
tensor
<tf.Tensor: shape=(10, 1), dtype=float32, numpy=
array([[0. ],
[0.1],
[0.2],
[0.3],
[0.4],
[0.5],
[0.6],
[0.7],
[0.8],
[0.9]], dtype=float32)>
K.cast(K.equal(a, K.max(a)), dtype='int8')
<tf.Tensor: shape=(10, 1), dtype=int8, numpy=
array([[0],
[0],
[0],
[0],
[0],
[0],
[0],
[0],
[0],
[1]], dtype=int8)>