tf.One_hot返回数组中充满0&#x27
我是深度学习的新手,我正在尝试对此张量
E = tf.constant(np.random.randint(1,100,size = 10))
E
输出
进行一个热门编码< tf.tensor:shape =(10,),dtype = int64,numpy = array([48,85,75,75,25,28,49,3,3,51,47,47,96])>
使用tf.one_hot()后,返回的数组
tf.one_hot(E,depth=10)
在返回的张量中输出
<tf.Tensor: shape=(10, 10), dtype=float32, numpy=
array([[0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 1., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]], dtype=float32)>
大多数热编码值是 0.,0.,0.,0。,0。,0。,0。,0。
[ 许多值的向量?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的随机整数在1-100范围内,则需要将深度= 100 保留在One_hot函数中。
相反,您可以将随机整数的范围降低到1-10。
这个想法是,如果您的数字范围在1-100之间,则需要尽可能多的位来表示单热编码,而您尚未通过将深度限制为10来提供。
输出:
If your random integers are in the range 1-100, you'll need to keep depth=100 in the one_hot function.
Conversely, you can reduce the range of random integers to 1-10.
The idea is that if your number ranges between 1-100, it needs as many bits to represent the one-hot encoding, which you haven't provided by restricting the depth to 10.
Output: