From 8f664a5c49535e2176b63d0d21c50702c92bf0ca Mon Sep 17 00:00:00 2001 From: yukavio <67678385+yukavio@users.noreply.github.com> Date: Tue, 10 Nov 2020 15:04:56 +0800 Subject: [PATCH] fix one_hot example code (#28432) --- python/paddle/nn/functional/input.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/python/paddle/nn/functional/input.py b/python/paddle/nn/functional/input.py index 2e4bbd99a72..f6f367bf23d 100644 --- a/python/paddle/nn/functional/input.py +++ b/python/paddle/nn/functional/input.py @@ -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.]] """ -- GitLab