@@ -4521,7 +4521,10 @@ def reduce_mean(input, dim=None, keep_dim=False, name=None):
4521
4521
Examples:
4522
4522
.. code-block:: python
4523
4523
4524
+ import paddle
4524
4525
import paddle.fluid as fluid
4526
+ paddle.enable_static()
4527
+
4525
4528
# x is a Tensor variable with following elements:
4526
4529
# [[0.2, 0.3, 0.5, 0.9]
4527
4530
# [0.1, 0.2, 0.6, 0.7]]
@@ -5160,7 +5163,10 @@ def matmul(x, y, transpose_x=False, transpose_y=False, alpha=1.0, name=None):
5160
5163
# x: [M], y: [N]
5161
5164
# fluid.layers.matmul(x, y, True, True) # out: [M, N]
5162
5165
5166
+ import paddle
5163
5167
import paddle.fluid as fluid
5168
+ paddle.enable_static()
5169
+
5164
5170
x = fluid.layers.data(name='x', shape=[2, 3], dtype='float32')
5165
5171
y = fluid.layers.data(name='y', shape=[3, 2], dtype='float32')
5166
5172
out = fluid.layers.matmul(x, y, True, True)
@@ -5999,7 +6005,10 @@ def one_hot(input, depth, allow_out_of_range=False):
5999
6005
Examples:
6000
6006
.. code-block:: python
6001
6007
6008
+ import paddle
6002
6009
import paddle.fluid as fluid
6010
+ paddle.enable_static()
6011
+
6003
6012
# Correspond to the first example above, where label.shape is [4, 1] and one_hot_label.shape is [4, 4].
6004
6013
label = fluid.data(name="label", shape=[4, 1], dtype="int64")
6005
6014
one_hot_label = fluid.layers.one_hot(input=label, depth=4)
@@ -8363,7 +8372,10 @@ def gather(input, index, overwrite=True):
8363
8372
8364
8373
.. code-block:: python
8365
8374
8375
+ import paddle
8366
8376
import paddle.fluid as fluid
8377
+ paddle.enable_static()
8378
+
8367
8379
x = fluid.data(name='x', shape=[-1, 5], dtype='float32')
8368
8380
index = fluid.data(name='index', shape=[-1, 1], dtype='int32')
8369
8381
output = fluid.layers.gather(x, index)
@@ -8453,7 +8465,10 @@ def gather_nd(input, index, name=None):
8453
8465
8454
8466
.. code-block:: python
8455
8467
8468
+ import paddle
8456
8469
import paddle.fluid as fluid
8470
+ paddle.enable_static()
8471
+
8457
8472
x = fluid.data(name='x', shape=[3, 4, 5], dtype='float32')
8458
8473
index = fluid.data(name='index', shape=[2, 2], dtype='int32')
8459
8474
output = fluid.layers.gather_nd(x, index)
@@ -8488,6 +8503,7 @@ def scatter(input, index, updates, name=None, overwrite=True):
8488
8503
Output is obtained by updating the input on selected indices based on updates.
8489
8504
8490
8505
.. code-block:: python
8506
+
8491
8507
import numpy as np
8492
8508
8493
8509
#input:
@@ -8529,8 +8545,10 @@ def scatter(input, index, updates, name=None, overwrite=True):
8529
8545
8530
8546
.. code-block:: python
8531
8547
8548
+ import paddle
8532
8549
import numpy as np
8533
8550
import paddle.fluid as fluid
8551
+ paddle.enable_static()
8534
8552
8535
8553
input = fluid.layers.data(name='data', shape=[3, 2], dtype='float32', append_batch_size=False)
8536
8554
index = fluid.layers.data(name='index', shape=[4], dtype='int64', append_batch_size=False)
@@ -8871,8 +8889,10 @@ def selu(x, scale=None, alpha=None, name=None):
8871
8889
8872
8890
.. code-block:: python
8873
8891
8892
+ import paddle
8874
8893
import paddle.fluid as fluid
8875
8894
import numpy as np
8895
+ paddle.enable_static()
8876
8896
8877
8897
inputs = fluid.layers.data(name="x", shape=[2, 2], dtype="float32")
8878
8898
output = fluid.layers.selu(inputs)
@@ -10480,22 +10500,24 @@ def expand_as(x, target_tensor, name=None):
10480
10500
Examples:
10481
10501
.. code-block:: python
10482
10502
10483
- import paddle.fluid as fluid
10484
- import numpy as np
10503
+ import paddle
10504
+ import paddle.fluid as fluid
10505
+ import numpy as np
10506
+ paddle.enable_static()
10485
10507
10486
- data = fluid.layers.data(name="data", shape=[-1,10], dtype='float64')
10487
- target_tensor = fluid.layers.data(
10488
- name="target_tensor", shape=[-1,20], dtype='float64')
10489
- result = fluid.layers.expand_as(x=data, target_tensor=target_tensor)
10490
- use_cuda = False
10491
- place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace()
10492
- exe = fluid.Executor(place)
10493
- exe.run(fluid.default_startup_program())
10494
- x = np.random.rand(3,10)
10495
- y = np.random.rand(3,20)
10496
- output= exe.run(feed={"data":x,"target_tensor":y},fetch_list=[result.name])
10497
- print(output[0].shape)
10498
- #(3,20)
10508
+ data = fluid.layers.data(name="data", shape=[-1,10], dtype='float64')
10509
+ target_tensor = fluid.layers.data(
10510
+ name="target_tensor", shape=[-1,20], dtype='float64')
10511
+ result = fluid.layers.expand_as(x=data, target_tensor=target_tensor)
10512
+ use_cuda = False
10513
+ place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace()
10514
+ exe = fluid.Executor(place)
10515
+ exe.run(fluid.default_startup_program())
10516
+ x = np.random.rand(3,10)
10517
+ y = np.random.rand(3,20)
10518
+ output= exe.run(feed={"data":x,"target_tensor":y},fetch_list=[result.name])
10519
+ print(output[0].shape)
10520
+ #(3,20)
10499
10521
10500
10522
"""
10501
10523
if in_dygraph_mode():
@@ -10576,7 +10598,9 @@ def uniform_random_batch_size_like(input,
10576
10598
Examples:
10577
10599
.. code-block:: python
10578
10600
10601
+ import paddle
10579
10602
import paddle.fluid as fluid
10603
+ paddle.enable_static()
10580
10604
10581
10605
# example 1:
10582
10606
input = fluid.data(name="input", shape=[1, 3], dtype='float32')
@@ -10649,7 +10673,9 @@ def gaussian_random(shape,
10649
10673
Examples:
10650
10674
.. code-block:: python
10651
10675
10676
+ import paddle
10652
10677
import paddle.fluid as fluid
10678
+ paddle.enable_static()
10653
10679
10654
10680
# example 1:
10655
10681
# attr shape is a list which doesn't contain Tensor.
@@ -10677,7 +10703,8 @@ def gaussian_random(shape,
10677
10703
10678
10704
.. code-block:: python
10679
10705
10680
- # declarative mode
10706
+ # declarative mode
10707
+ # required: skiptest
10681
10708
import numpy as np
10682
10709
from paddle import fluid
10683
10710
@@ -10816,7 +10843,10 @@ def gaussian_random_batch_size_like(input,
10816
10843
Examples:
10817
10844
.. code-block:: python
10818
10845
10846
+ import paddle
10819
10847
import paddle.fluid as fluid
10848
+ paddle.enable_static()
10849
+
10820
10850
input = fluid.data(name="input", shape=[13, 11], dtype='float32')
10821
10851
10822
10852
out = fluid.layers.gaussian_random_batch_size_like(
@@ -11422,7 +11452,9 @@ def size(input):
11422
11452
Examples:
11423
11453
.. code-block:: python
11424
11454
11455
+ import paddle
11425
11456
import paddle.fluid.layers as layers
11457
+ paddle.enable_static()
11426
11458
11427
11459
input = layers.data(
11428
11460
name="input", shape=[3, 100], dtype="float32", append_batch_size=False)
@@ -12525,7 +12557,10 @@ def mean(x, name=None):
12525
12557
Examples:
12526
12558
.. code-block:: python
12527
12559
12560
+ import paddle
12528
12561
import paddle.fluid as fluid
12562
+ paddle.enable_static()
12563
+
12529
12564
input = fluid.layers.data(
12530
12565
name='data', shape=[2, 3], dtype='float32')
12531
12566
mean = fluid.layers.mean(input)
@@ -15195,7 +15230,9 @@ def uniform_random(shape, dtype='float32', min=-1.0, max=1.0, seed=0,
15195
15230
Examples:
15196
15231
.. code-block:: python
15197
15232
15233
+ import paddle
15198
15234
import paddle.fluid as fluid
15235
+ paddle.enable_static()
15199
15236
15200
15237
# example 1:
15201
15238
# attr shape is a list which doesn't contain Tensor.
0 commit comments