未验证 提交 8f664a5c 编写于 作者: Y yukavio 提交者: GitHub

fix one_hot example code (#28432)

上级 53e9aa94
......@@ -74,15 +74,14 @@ def one_hot(x, num_classes, name=None):
import paddle
# Correspond to the first example above, where label.shape is 4 and one_hot_label.shape is [4, 4].
label = paddle.static.data(name="label", shape=[4, 1], dtype="int64")
label = paddle.to_tensor([1, 1, 3, 0], dtype='int64')
# label.shape = [4]
# label.data = [1, 1, 3, 0]
one_hot_label = paddle.nn.functional.one_hot(x=label, num_classes=4)
one_hot_label = paddle.nn.functional.one_hot(label, num_classes=4)
# one_hot_label.shape = [4, 4]
# one_hot_label.data = [[0., 1., 0., 0.],
# [0., 1., 0., 0.],
# [0., 0., 0., 1.],
# [1., 0., 0., 0.]]
# one_hot_label = [[0., 1., 0., 0.],
# [0., 1., 0., 0.],
# [0., 0., 0., 1.],
# [1., 0., 0., 0.]]
"""
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册