gpt4 book ai didi

python - 最大值的二元向量

转载 作者:行者123 更新时间:2023-11-30 21:59:49 26 4
gpt4 key购买 nike

如果我有一个像这样的向量

[2,5,8,1]

如何将其转换为二进制向量,其中除了最大元素将表示为 1 之外,所有元素均为 0?

[0,0,1,0]

我希望这可以在 Tensorflow 中优雅地完成。

最佳答案

这里:

X = np.array([2,5,8,1])
one_hot = tf.one_hot(indices=tf.argmax(X), depth=tf.shape(X)[0])

关于python - 最大值的二元向量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54493814/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com