import tensorflow.keras.utils.to_categorical code example
Example: tensorflow.keras.utils.to_categorical
a = tf.keras.utils.to_categorical([0, 1, 2, 3], num_classes=4)a = tf.constant(a, shape=[4, 4])print(a)tf.Tensor( [[1. 0. 0. 0.] [0. 1. 0. 0.] [0. 0. 1. 0.] [0. 0. 0. 1.]], shape=(4, 4), dtype=float32)