From c61ac9e5684a1000598a89b38df520abfa296af6 Mon Sep 17 00:00:00 2001 From: BrilliantYuKaimin <91609464+BrilliantYuKaimin@users.noreply.github.com> Date: Thu, 2 Jun 2022 18:40:24 +0800 Subject: [PATCH] Update search.py --- python/paddle/tensor/search.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/python/paddle/tensor/search.py b/python/paddle/tensor/search.py index 55c331bc20248..dddad92aafe3f 100644 --- a/python/paddle/tensor/search.py +++ b/python/paddle/tensor/search.py @@ -567,13 +567,13 @@ def where(condition, x=None, y=None, name=None): \begin{cases} x_i, & \text{if} \ condition_i \ \text{is} \ True \\ y_i, & \text{if} \ condition_i \ \text{is} \ False \\ - \end{cases} + \end{cases}. Notes: - ``paddle.where(condition)`` is identical to ``paddle.nonzero(condition, as_tuple=True)``. + ``numpy.where(condition)`` is identical to ``paddle.nonzero(condition, as_tuple=True)``, please refer to :ref:`api_tensor_search_nonzero`. Args: - condition (Tensor): The condition to choose x or y. When True(nonzero), yield x, otherwise yield y. + condition (Tensor): The condition to choose x or y. When True (nonzero), yield x, otherwise yield y. x (Tensor|scalar, optional): A Tensor or scalar to choose when the condition is True with data type of float32, float64, int32 or int64. Either both or neither of x and y should be given. y (Tensor|scalar, optional): A Tensor or scalar to choose when the condition is False with data type of float32, float64, int32 or int64. Either both or neither of x and y should be given. name (str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None. @@ -583,22 +583,22 @@ def where(condition, x=None, y=None, name=None): Examples: .. code-block:: python - :name:where-example + :name:where-example - import paddle + import paddle - x = paddle.to_tensor([0.9383, 0.1983, 3.2, 1.2]) - y = paddle.to_tensor([1.0, 1.0, 1.0, 1.0]) - out = paddle.where(x>1, x, y) + x = paddle.to_tensor([0.9383, 0.1983, 3.2, 1.2]) + y = paddle.to_tensor([1.0, 1.0, 1.0, 1.0]) + out = paddle.where(x>1, x, y) - print(out) - #out: [1.0, 1.0, 3.2, 1.2] + print(out) + #out: [1.0, 1.0, 3.2, 1.2] - out = paddle.where(x>1) - print(out) - #out: (Tensor(shape=[2, 1], dtype=int64, place=CPUPlace, stop_gradient=True, - # [[2], - # [3]]),) + out = paddle.where(x>1) + print(out) + #out: (Tensor(shape=[2, 1], dtype=int64, place=CPUPlace, stop_gradient=True, + # [[2], + # [3]]),) """ if np.isscalar(x): x = paddle.full([1], x, np.array([x]).dtype.name)