Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cherry-pick2.0]Update doc of paddle.to tensor #26968

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions python/paddle/fluid/layers/nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -12163,13 +12163,10 @@ def logical_and(x, y, out=None, name=None):
.. code-block:: python

import paddle
import numpy as np

paddle.disable_static()
x_data = np.array([True], dtype=np.bool)
y_data = np.array([True, False, True, False], dtype=np.bool)
x = paddle.to_tensor(x_data)
y = paddle.to_tensor(y_data)
x = paddle.to_tensor([True])
y = paddle.to_tensor([True, False, True, False])
res = paddle.logical_and(x, y)
print(res.numpy()) # [True False True False]
"""
Expand Down Expand Up @@ -12282,11 +12279,9 @@ def logical_not(x, out=None, name=None):
Examples:
.. code-block:: python
import paddle
import numpy as np

paddle.disable_static()
x_data = np.array([True, False, True, False], dtype=np.bool)
x = paddle.to_variable(x_data)
x = paddle.to_tensor([True, False, True, False])
res = paddle.logical_not(x)
print(res.numpy()) # [False True False True]
"""
Expand Down
89 changes: 23 additions & 66 deletions python/paddle/fluid/layers/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,11 @@
Examples:
.. code-block:: python

import numpy as np
import paddle
import paddle.nn.functional as F
paddle.disable_static()

x_data = np.array([-0.4, -0.2, 0.1, 0.3])
x = paddle.to_variable(x_data)
x = paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])
out = F.sigmoid(x)
print(out.numpy())
# [0.40131234 0.450166 0.52497919 0.57444252]
Expand All @@ -103,13 +101,11 @@
Examples:
.. code-block:: python

import numpy as np
import paddle
import paddle.nn.functional as F
paddle.disable_static()

x_data = np.array([-0.4, -0.2, 0.1, 0.3])
x = paddle.to_variable(x_data)
x = paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])
out = F.logsigmoid(x)
print(out.numpy())
# [-0.91301525 -0.79813887 -0.64439666 -0.55435524]
Expand All @@ -120,12 +116,10 @@
Examples:
.. code-block:: python

import numpy as np
import paddle
paddle.disable_static()

x_data = np.array([-0.4, -0.2, 0.1, 0.3])
x = paddle.to_variable(x_data)
x = paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])
out = paddle.exp(x)
print(out.numpy())
# [0.67032005 0.81873075 1.10517092 1.34985881]
Expand All @@ -136,12 +130,10 @@
Examples:
.. code-block:: python

import numpy as np
import paddle
paddle.disable_static()

x_data = np.array([-0.4, -0.2, 0.1, 0.3])
x = paddle.to_variable(x_data)
x = paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])
out = paddle.tanh(x)
print(out.numpy())
# [-0.37994896 -0.19737532 0.09966799 0.29131261]
Expand All @@ -152,12 +144,10 @@
Examples:
.. code-block:: python

import numpy as np
import paddle
paddle.disable_static()

x_data = np.array([-0.4, -0.2, 0.1, 0.3])
x = paddle.to_variable(x_data)
x = paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])
out = paddle.atan(x)
print(out.numpy())
# [-0.38050638 -0.19739556 0.09966865 0.29145679]
Expand All @@ -170,11 +160,10 @@

import paddle
import paddle.nn.functional as F
import numpy as np

paddle.disable_static()

x = paddle.to_tensor(np.array([-0.4, -0.2, 0.1, 0.3]))
x = paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])
out = F.tanhshrink(x) # [-0.020051, -0.00262468, 0.000332005, 0.00868739]

""")
Expand All @@ -183,12 +172,10 @@
Examples:
.. code-block:: python

import numpy as np
import paddle
paddle.disable_static()

x_data = np.array([0.1, 0.2, 0.3, 0.4])
x = paddle.to_variable(x_data)
x = paddle.to_tensor([0.1, 0.2, 0.3, 0.4])
out = paddle.sqrt(x)
print(out.numpy())
# [0.31622777 0.4472136 0.54772256 0.63245553]
Expand All @@ -199,12 +186,10 @@
Examples:
.. code-block:: python

import numpy as np
import paddle
paddle.disable_static()

x_data = np.array([0.1, 0.2, 0.3, 0.4])
x = paddle.to_variable(x_data)
x = paddle.to_tensor([0.1, 0.2, 0.3, 0.4])
out = paddle.rsqrt(x)
print(out.numpy())
# [3.16227766 2.23606798 1.82574186 1.58113883]
Expand All @@ -215,12 +200,10 @@
Examples:
.. code-block:: python

import numpy as np
import paddle
paddle.disable_static()

x_data = np.array([-0.4, -0.2, 0.1, 0.3])
x = paddle.to_variable(x_data)
x = paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])
out = paddle.abs(x)
print(out.numpy())
# [0.4 0.2 0.1 0.3]
Expand All @@ -231,12 +214,10 @@
Examples:
.. code-block:: python

import numpy as np
import paddle
paddle.disable_static()

x_data = np.array([-0.4, -0.2, 0.1, 0.3])
x = paddle.to_variable(x_data)
x = paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])
out = paddle.ceil(x)
print(out.numpy())
# [-0. -0. 1. 1.]
Expand All @@ -247,12 +228,10 @@
Examples:
.. code-block:: python

import numpy as np
import paddle
paddle.disable_static()

x_data = np.array([-0.4, -0.2, 0.1, 0.3])
x = paddle.to_variable(x_data)
x = paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])
out = paddle.floor(x)
print(out.numpy())
# [-1. -1. 0. 0.]
Expand All @@ -263,12 +242,10 @@
Examples:
.. code-block:: python

import numpy as np
import paddle
paddle.disable_static()

x_data = np.array([-0.4, -0.2, 0.1, 0.3])
x = paddle.to_variable(x_data)
x = paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])
out = paddle.cos(x)
print(out.numpy())
# [0.92106099 0.98006658 0.99500417 0.95533649]
Expand All @@ -279,12 +256,10 @@
Examples:
.. code-block:: python

import numpy as np
import paddle
paddle.disable_static()

x_data = np.array([-0.4, -0.2, 0.1, 0.3])
x = paddle.to_variable(x_data)
x = paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])
out = paddle.acos(x)
print(out.numpy())
# [1.98231317 1.77215425 1.47062891 1.26610367]
Expand All @@ -295,12 +270,10 @@
Examples:
.. code-block:: python

import numpy as np
import paddle
paddle.disable_static()

x_data = np.array([-0.4, -0.2, 0.1, 0.3])
x = paddle.to_variable(x_data)
x = paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])
out = paddle.sin(x)
print(out.numpy())
# [-0.38941834 -0.19866933 0.09983342 0.29552021]
Expand All @@ -311,12 +284,10 @@
Examples:
.. code-block:: python

import numpy as np
import paddle
paddle.disable_static()

x_data = np.array([-0.4, -0.2, 0.1, 0.3])
x = paddle.to_variable(x_data)
x = paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])
out = paddle.asin(x)
print(out.numpy())
# [-0.41151685 -0.20135792 0.10016742 0.30469265]
Expand All @@ -327,12 +298,10 @@
Examples:
.. code-block:: python

import numpy as np
import paddle
paddle.disable_static()

x_data = np.array([-0.4, -0.2, 0.1, 0.3])
x = paddle.to_variable(x_data)
x = paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])
out = paddle.cosh(x)
print(out.numpy())
# [1.08107237 1.02006676 1.00500417 1.04533851]
Expand All @@ -343,12 +312,10 @@
Examples:
.. code-block:: python

import numpy as np
import paddle
paddle.disable_static()

x_data = np.array([-0.4, -0.2, 0.1, 0.3])
x = paddle.to_variable(x_data)
x = paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])
out = paddle.sinh(x)
print(out.numpy())
# [-0.41075233 -0.201336 0.10016675 0.30452029]
Expand All @@ -359,12 +326,10 @@
Examples:
.. code-block:: python

import numpy as np
import paddle
paddle.disable_static()

x_data = np.array([-0.5, -0.2, 0.6, 1.5])
x = paddle.to_variable(x_data)
x = paddle.to_tensor([-0.5, -0.2, 0.6, 1.5])
out = paddle.round(x)
print(out.numpy())
# [-1. -0. 1. 2.]
Expand All @@ -375,12 +340,10 @@
Examples:
.. code-block:: python

import numpy as np
import paddle
paddle.disable_static()

x_data = np.array([-0.4, -0.2, 0.1, 0.3])
x = paddle.to_variable(x_data)
x = paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])
out = paddle.reciprocal(x)
print(out.numpy())
# [-2.5 -5. 10. 3.33333333]
Expand All @@ -391,12 +354,10 @@
Examples:
.. code-block:: python

import numpy as np
import paddle
paddle.disable_static()

x_data = np.array([-0.4, -0.2, 0.1, 0.3])
x = paddle.to_variable(x_data)
x = paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])
out = paddle.square(x)
print(out.numpy())
# [0.16 0.04 0.01 0.09]
Expand All @@ -409,11 +370,10 @@

import paddle
import paddle.nn.functional as F
import numpy as np

paddle.disable_static()

x = paddle.to_tensor(np.array([-0.4, -0.2, 0.1, 0.3]))
x = paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])
out = F.softplus(x) # [0.513015, 0.598139, 0.744397, 0.854355]

""")
Expand All @@ -424,11 +384,10 @@

import paddle
import paddle.nn.functional as F
import numpy as np

paddle.disable_static()

x = paddle.to_tensor(np.array([-0.4, -0.2, 0.1, 0.3]))
x = paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])
out = F.softsign(x) # [-0.285714, -0.166667, 0.0909091, 0.230769]

""")
Expand Down Expand Up @@ -761,11 +720,9 @@ def erf(x, name=None):

.. code-block:: python

import numpy as np
import paddle
paddle.disable_static()
x_data = np.array([-0.4, -0.2, 0.1, 0.3])
x = paddle.to_tensor(x_data)
x = paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])
out = paddle.erf(x)
print(out.numpy())
# [-0.42839236 -0.22270259 0.11246292 0.32862676]
Expand Down
Loading