提交 30f297f6 编写于 作者: L Leo Chen 提交者: GitHub

Revert "update 1.8 apis, test=develop (#2052)"

This reverts commit 8ba38e07.
上级 8ba38e07
......@@ -7,7 +7,6 @@ fluid.dygraph
dygraph/BackwardStrategy.rst
dygraph/BatchNorm.rst
dygraph/BCELoss.rst
dygraph/BilinearTensorProduct.rst
dygraph/Conv2D.rst
dygraph/Conv2DTranspose.rst
......@@ -28,22 +27,17 @@ fluid.dygraph
dygraph/ExponentialDecay.rst
dygraph/grad.rst
dygraph/GroupNorm.rst
dygraph/GRUCell.rst
dygraph/GRUUnit.rst
dygraph/guard.rst
dygraph/InstanceNorm.rst
dygraph/InverseTimeDecay.rst
dygraph/L1Loss.rst
dygraph/Layer.rst
dygraph/LayerList.rst
dygraph/LayerNorm.rst
dygraph/Linear.rst
dygraph/load_dygraph.rst
dygraph/LSTMCell.rst
dygraph/MSELoss.rst
dygraph/NaturalExpDecay.rst
dygraph/NCE.rst
dygraph/NLLLoss.rst
dygraph/no_grad.rst
dygraph/NoamDecay.rst
dygraph/ParallelEnv.rst
......
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_dygraph_BCELoss:
BCELoss
-------
.. autoclass:: paddle.fluid.dygraph.BCELoss
:members:
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_dygraph_InstanceNorm:
InstanceNorm
------------
.. autoclass:: paddle.fluid.dygraph.InstanceNorm
:members:
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_dygraph_MSELoss:
MSELoss
-------
.. autoclass:: paddle.fluid.dygraph.MSELoss
:members:
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_dygraph_NLLLoss:
NLLLoss
-------
.. autoclass:: paddle.fluid.dygraph.NLLLoss
:members:
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_dygraph_ProgramTranslator:
ProgramTranslator
-----------------
.. autoclass:: paddle.fluid.dygraph.ProgramTranslator
:members:
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_dygraph_declarative:
declarative
-----------
.. autofunction:: paddle.fluid.dygraph.declarative
:noindex:
......@@ -10,6 +10,33 @@ done
python gen_doc.py --module_name "" --module_prefix "" --output fluid --output_name fluid --to_multiple_files True
python gen_module_index.py fluid fluid
# tensor
for module in math random stat
do
python gen_doc.py --module_name ${module} --module_prefix ${module} --output ${module} --output_name tensor --to_multiple_files True --output_dir tensor
python gen_module_index.py tensor.${module} ${module}
done
python gen_module_index.py tensor paddle.tensor
for module in math manipulation
do
python gen_doc.py --module_name tensor.${module} --module_prefix tensor.${module} --output tensor/${module} --output_name complex --to_multiple_files True --output_dir complex
python gen_module_index.py complex.tensor.${module} ${module}
done
python gen_module_index.py complex.tensor tensor
python gen_module_index.py complex paddle.complex
# nn
for module in loss
do
python gen_doc.py --module_name ${module} --module_prefix ${module} --output ${module} --output_name nn --to_multiple_files True --output_dir nn
python gen_module_index.py nn.${module} ${module}
done
python gen_doc.py --module_name "" --module_prefix "" --output nn --output_name nn --to_multiple_files True
python gen_module_index.py nn paddle.nn
# index.rst
python gen_index.py
......
......@@ -6,6 +6,9 @@ API Reference
:maxdepth: 1
../api_guides/index_en.rst
complex.rst
nn.rst
tensor.rst
fluid.rst
backward.rst
clip.rst
......@@ -14,6 +17,7 @@ API Reference
dataset.rst
dygraph.rst
executor.rst
index.rst
initializer.rst
io.rst
layers.rst
......
......@@ -11,13 +11,9 @@ fluid.layers
layers/adaptive_pool2d.rst
layers/adaptive_pool3d.rst
layers/add_position_encoding.rst
layers/addcmul.rst
layers/addmm.rst
layers/affine_channel.rst
layers/affine_grid.rst
layers/allclose.rst
layers/anchor_generator.rst
layers/arange.rst
layers/argmax.rst
layers/argmin.rst
layers/argsort.rst
......@@ -36,7 +32,6 @@ fluid.layers
layers/BeamSearchDecoder.rst
layers/bilinear_tensor_product.rst
layers/bipartite_match.rst
layers/bmm.rst
layers/box_clip.rst
layers/box_coder.rst
layers/box_decoder_and_assign.rst
......@@ -48,7 +43,6 @@ fluid.layers
layers/ceil.rst
layers/center_loss.rst
layers/chunk_eval.rst
layers/clamp.rst
layers/clip.rst
layers/clip_by_norm.rst
layers/collect_fpn_proposals.rst
......@@ -70,7 +64,6 @@ fluid.layers
layers/crf_decoding.rst
layers/crop.rst
layers/crop_tensor.rst
layers/cross.rst
layers/cross_entropy.rst
layers/ctc_greedy_decoder.rst
layers/cumsum.rst
......@@ -83,11 +76,8 @@ fluid.layers
layers/density_prior_box.rst
layers/detection_output.rst
layers/diag.rst
layers/diag_embed.rst
layers/dice_loss.rst
layers/dist.rst
layers/distribute_fpn_proposals.rst
layers/dot.rst
layers/double_buffer.rst
layers/dropout.rst
layers/dynamic_decode.rst
......@@ -98,7 +88,6 @@ fluid.layers
layers/edit_distance.rst
layers/elementwise_add.rst
layers/elementwise_div.rst
layers/elementwise_equal.rst
layers/elementwise_floordiv.rst
layers/elementwise_max.rst
layers/elementwise_min.rst
......@@ -120,11 +109,8 @@ fluid.layers
layers/fill_constant_batch_size_like.rst
layers/filter_by_instag.rst
layers/flatten.rst
layers/flip.rst
layers/floor.rst
layers/fsp_matrix.rst
layers/full.rst
layers/full_like.rst
layers/gather.rst
layers/gather_nd.rst
layers/gather_tree.rst
......@@ -155,16 +141,13 @@ fluid.layers
layers/image_resize.rst
layers/image_resize_short.rst
layers/increment.rst
layers/index_select.rst
layers/inplace_abn.rst
layers/instance_norm.rst
layers/interpolate.rst
layers/inverse_time_decay.rst
layers/iou_similarity.rst
layers/is_empty.rst
layers/isfinite.rst
layers/kldiv_loss.rst
layers/kron.rst
layers/l2_normalize.rst
layers/label_smooth.rst
layers/layer_norm.rst
......@@ -179,15 +162,12 @@ fluid.layers
layers/lod_append.rst
layers/lod_reset.rst
layers/log.rst
layers/log1p.rst
layers/log_loss.rst
layers/log_softmax.rst
layers/logical_and.rst
layers/logical_not.rst
layers/logical_or.rst
layers/logical_xor.rst
layers/logsigmoid.rst
layers/logsumexp.rst
layers/lrn.rst
layers/lstm.rst
layers/lstm_unit.rst
......@@ -198,7 +178,6 @@ fluid.layers
layers/mean.rst
layers/mean_iou.rst
layers/merge_selected_rows.rst
layers/meshgrid.rst
layers/mse_loss.rst
layers/mul.rst
layers/multi_box_head.rst
......@@ -208,7 +187,6 @@ fluid.layers
layers/natural_exp_decay.rst
layers/nce.rst
layers/noam_decay.rst
layers/nonzero.rst
layers/Normal.rst
layers/not_equal.rst
layers/npair_loss.rst
......@@ -232,10 +210,7 @@ fluid.layers
layers/psroi_pool.rst
layers/py_func.rst
layers/py_reader.rst
layers/randint.rst
layers/randn.rst
layers/random_crop.rst
layers/randperm.rst
layers/range.rst
layers/rank.rst
layers/rank_loss.rst
......@@ -263,7 +238,6 @@ fluid.layers
layers/roi_align.rst
layers/roi_perspective_transform.rst
layers/roi_pool.rst
layers/roll.rst
layers/round.rst
layers/row_conv.rst
layers/rpn_target_assign.rst
......@@ -327,7 +301,6 @@ fluid.layers
layers/swish.rst
layers/Switch.rst
layers/switch_case.rst
layers/t.rst
layers/tanh.rst
layers/tanh_shrink.rst
layers/target_assign.rst
......@@ -336,11 +309,8 @@ fluid.layers
layers/tensor_array_to_tensor.rst
layers/thresholded_relu.rst
layers/topk.rst
layers/trace.rst
layers/TrainingHelper.rst
layers/transpose.rst
layers/tril.rst
layers/triu.rst
layers/unfold.rst
layers/Uniform.rst
layers/uniform_random.rst
......
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_addcmul:
addcmul
-------
.. autofunction:: paddle.fluid.layers.addcmul
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_addmm:
addmm
-----
.. autofunction:: paddle.fluid.layers.addmm
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_allclose:
allclose
--------
.. autofunction:: paddle.fluid.layers.allclose
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_arange:
arange
------
.. autofunction:: paddle.fluid.layers.arange
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_clamp:
clamp
-----
.. autofunction:: paddle.fluid.layers.clamp
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_cross:
cross
-----
.. autofunction:: paddle.fluid.layers.cross
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_diag_embed:
diag_embed
----------
.. autofunction:: paddle.fluid.layers.diag_embed
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_elementwise_equal:
elementwise_equal
-----------------
.. autofunction:: paddle.fluid.layers.elementwise_equal
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_full_like:
full_like
---------
.. autofunction:: paddle.fluid.layers.full_like
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_index_select:
index_select
------------
.. autofunction:: paddle.fluid.layers.index_select
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_interpolate:
interpolate
-----------
.. autofunction:: paddle.fluid.layers.interpolate
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_log1p:
log1p
-----
.. autofunction:: paddle.fluid.layers.log1p
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_log_softmax:
log_softmax
-----------
.. autofunction:: paddle.fluid.layers.log_softmax
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_logsumexp:
logsumexp
---------
.. autofunction:: paddle.fluid.layers.logsumexp
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_nonzero:
nonzero
-------
.. autofunction:: paddle.fluid.layers.nonzero
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_randn:
randn
-----
.. autofunction:: paddle.fluid.layers.randn
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_roll:
roll
----
.. autofunction:: paddle.fluid.layers.roll
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_trace:
trace
-----
.. autofunction:: paddle.fluid.layers.trace
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_tril:
tril
----
.. autofunction:: paddle.fluid.layers.tril
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_triu:
triu
----
.. autofunction:: paddle.fluid.layers.triu
:noindex:
=========
paddle.nn
=========
.. toctree::
:maxdepth: 1
nn/loss.rst
====
loss
====
.. toctree::
:maxdepth: 1
loss/BCELoss.rst
loss/CrossEntropyLoss.rst
loss/L1Loss.rst
loss/MSELoss.rst
loss/NLLLoss.rst
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_dygraph_L1Loss:
.. _api_nn_loss_L1Loss:
L1Loss
------
.. autoclass:: paddle.fluid.dygraph.L1Loss
.. autoclass:: paddle.nn.loss.L1Loss
:members:
:inherited-members:
:noindex:
=============
paddle.tensor
=============
.. toctree::
:maxdepth: 1
tensor/linalg.rst
tensor/math.rst
tensor/random.rst
tensor/stat.rst
======
linalg
======
.. toctree::
:maxdepth: 1
linalg/dist.rst
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_meshgrid:
.. _api_tensor_linalg_dist:
meshgrid
dist
--------
.. autofunction:: paddle.fluid.layers.meshgrid
.. autofunction:: paddle.tensor.linalg.dist
:noindex:
====
math
====
.. toctree::
:maxdepth: 1
math/add.rst
math/addcmul.rst
math/addmm.rst
math/atan.rst
math/clamp.rst
math/div.rst
math/elementwise_sum.rst
math/log1p.rst
math/logsumexp.rst
math/max.rst
math/min.rst
math/mm.rst
math/mul.rst
math/pow.rst
math/sin.rst
math/sqrt.rst
math/sum.rst
math/tanh.rst
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_dot:
.. _api_tensor_math_add:
dot
add
---
.. autofunction:: paddle.fluid.layers.dot
.. autofunction:: paddle.tensor.math.add
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_dist:
.. _api_tensor_math_atan:
dist
atan
----
.. autofunction:: paddle.fluid.layers.dist
.. autofunction:: paddle.tensor.math.atan
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_bmm:
.. _api_tensor_math_div:
bmm
div
---
.. autofunction:: paddle.fluid.layers.bmm
.. autofunction:: paddle.tensor.math.div
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_ComplexVariable:
.. _api_tensor_math_elementwise_sum:
ComplexVariable
elementwise_sum
---------------
.. autoclass:: paddle.fluid.ComplexVariable
:members:
:inherited-members:
.. autofunction:: paddle.tensor.math.elementwise_sum
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_t:
.. _api_tensor_math_mm:
t
-
mm
--
.. autofunction:: paddle.fluid.layers.t
.. autofunction:: paddle.tensor.math.mm
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_tensor_math_mul:
mul
---
.. autofunction:: paddle.tensor.math.mul
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_tensor_math_pow:
pow
---
.. autofunction:: paddle.tensor.math.pow
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_tensor_math_sin:
sin
---
.. autofunction:: paddle.tensor.math.sin
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_full:
.. _api_tensor_math_sqrt:
full
sqrt
----
.. autofunction:: paddle.fluid.layers.full
.. autofunction:: paddle.tensor.math.sqrt
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_tensor_math_sum:
sum
---
.. autofunction:: paddle.tensor.math.sum
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_flip:
.. _api_tensor_math_tanh:
flip
tanh
----
.. autofunction:: paddle.fluid.layers.flip
.. autofunction:: paddle.tensor.math.tanh
:noindex:
======
random
======
.. toctree::
:maxdepth: 1
random/randint.rst
random/randn.rst
random/randperm.rst
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_kron:
.. _api_tensor_random_rand:
kron
rand
----
.. autofunction:: paddle.fluid.layers.kron
.. autofunction:: paddle.tensor.random.rand
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_randint:
.. _api_tensor_random_randint:
randint
-------
.. autofunction:: paddle.fluid.layers.randint
.. autofunction:: paddle.tensor.random.randint
:noindex:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_fluid_layers_randperm:
.. _api_tensor_random_randperm:
randperm
--------
.. autofunction:: paddle.fluid.layers.randperm
.. autofunction:: paddle.tensor.random.randperm
:noindex:
......@@ -10,7 +10,6 @@ fluid.dygraph
dygraph_cn/BackwardStrategy_cn.rst
dygraph_cn/BatchNorm_cn.rst
dygraph_cn/BCELoss_cn.rst
dygraph_cn/BilinearTensorProduct_cn.rst
dygraph_cn/Conv2D_cn.rst
dygraph_cn/Conv2DTranspose_cn.rst
......@@ -18,7 +17,6 @@ fluid.dygraph
dygraph_cn/Conv3DTranspose_cn.rst
dygraph_cn/CosineDecay_cn.rst
dygraph_cn/Dropout_cn.rst
dygraph_cn/declarative_cn.rst
dygraph_cn/Embedding_cn.rst
dygraph_cn/ExponentialDecay_cn.rst
dygraph_cn/FC_cn.rst
......@@ -26,18 +24,14 @@ fluid.dygraph
dygraph_cn/GroupNorm_cn.rst
dygraph_cn/GRUUnit_cn.rst
dygraph_cn/guard_cn.rst
dygraph_cn/InstanceNorm_cn.rst
dygraph_cn/InverseTimeDecay_cn.rst
dygraph_cn/L1Loss_cn.rst
dygraph_cn/Layer_cn.rst
dygraph_cn/LayerList_cn.rst
dygraph_cn/LayerNorm_cn.rst
dygraph_cn/Linear_cn.rst
dygraph_cn/load_dygraph_cn.rst
dygraph_cn/MSELoss_cn.rst
dygraph_cn/NaturalExpDecay_cn.rst
dygraph_cn/NCE_cn.rst
dygraph_cn/NLLLoss_cn.rst
dygraph_cn/NoamDecay_cn.rst
dygraph_cn/ParallelEnv_cn.rst
dygraph_cn/ParameterList_cn.rst
......@@ -47,7 +41,6 @@ fluid.dygraph
dygraph_cn/Pool2D_cn.rst
dygraph_cn/PRelu_cn.rst
dygraph_cn/prepare_context_cn.rst
dygraph_cn/ProgramTranslator_cn.rst
dygraph_cn/save_dygraph_cn.rst
dygraph_cn/Sequential_cn.rst
dygraph_cn/SpectralNorm_cn.rst
......
L1Loss
-------------------------------
.. py:function:: paddle.fluid.layers.L1Loss(reduction='mean')
该接口用于创建一个L1Loss的可调用类,L1Loss计算输入input和标签label间的 `L1 loss` 损失。
该损失函数的数学计算公式如下:
当 `reduction` 设置为 ``'none'`` 时,
.. math::
Out = |input - label|
当 `reduction` 设置为 ``'mean'`` 时,
.. math::
Out = MEAN(|input - label|)
当 `reduction` 设置为 ``'sum'`` 时,
.. math::
Out = SUM(|input - label|)
输入input和标签label的维度是[N, *], 其中N是batch_size, `*` 是任意其他维度。
如果 :attr:`reduction` 是 ``'none'``, 则输出Loss的维度为 [N, *], 与输入input相同。
如果 :attr:`reduction` 是 ``'mean'`` 或 ``'sum'``, 则输出Loss的维度为 [1]。
参数:
- **reduction** (string, 可选): - 指定应用于输出结果的计算方式,可选值有: ``'none'``, ``'mean'``, ``'sum'`` 。默认为 ``'mean'``,计算 `L1Loss` 的均值;设置为 ``'sum'`` 时,计算 `L1Loss` 的总和;设置为 ``'none'`` 时,则返回L1Loss。数据类型为string。
返回:返回计算L1Loss的可调用对象。
**代码示例**
.. code-block:: python
# declarative mode
import paddle.fluid as fluid
import numpy as np
import paddle
input = fluid.data(name="input", shape=[1])
label = fluid.data(name="label", shape=[1])
l1_loss = fluid.layers.L1Loss(reduction='mean')
output = l1_loss(input,label)
place = fluid.CPUPlace()
exe = fluid.Executor(place)
exe.run(fluid.default_startup_program())
input_data = np.array([1.5]).astype("float32")
label_data = np.array([1.7]).astype("float32")
output_data = exe.run(fluid.default_main_program(),
feed={"input":input_data, "label":label_data},
fetch_list=[output],
return_numpy=True)
print(output_data) # [array([0.2], dtype=float32)]
# imperative mode
import paddle.fluid.dygraph as dg
with dg.guard(place) as g:
input = dg.to_variable(input_data)
label = dg.to_variable(label_data)
l1_loss = fluid.layers.L1Loss(reduction='mean')
output = l1_loss(input,label)
print(output.numpy()) # [0.2]
NLLLoss
-------------------------------
**版本升级,文档正在开发中**
.. py:function:: paddle.fluid.dygraph.NLLLoss(weight=None, reduction='mean', ignore_index=-100)
该OP计算输入input和标签label间的 `negative log likelihood loss` 损失 ,可用于训练一个 `n` 类分类器。
如果提供 `weight` 参数的话,它是一个 `1-D` 的tensor, 里面的值对应类别的权重。当你的训练集样本
不均衡的话,使用这个参数是非常有用的。
该损失函数的数学计算公式如下:
当 `reduction` 设置为 `none` 时,损失函数的数学计算公式为:
.. math::
\ell(x, y) = L = \{l_1,\dots,l_N\}^\top, \quad
l_n = - w_{y_n} x_{n,y_n}, \quad
w_{c} = \text{weight}[c] \cdot \mathbb{1}\{c \not= \text{ignore_index}\},
其中 `N` 表示 `batch_size` 。如果 `reduction` 的值不是 `none` (默认为 `mean`),那么此时损失函数
的数学计算公式为:
.. math::
\ell(x, y) = \begin{cases}
\sum_{n=1}^N \frac{1}{\sum_{n=1}^N w_{y_n}} l_n, &
\text{if reduction} = \text{'mean';}\\
\sum_{n=1}^N l_n, &
\text{if reduction} = \text{'sum'.}
\end{cases}
参数:
- **input** (Variable): - 输入 `Tensor`, 其形状为 :math:`[N, C]` , 其中 `C` 为类别数。但是对于多维度的情形下,它的形状为 :math:`[N, C, d_1, d_2, ..., d_K]` 。数据类型为float32或float64。
- **label** (Variable): - 输入input对应的标签值。其形状为 :math:`[N,]` 或者 :math:`[N, d_1, d_2, ..., d_K]`, 数据类型为int64。
- **weight** (Variable, 可选): - 手动指定每个类别的权重。其默认为 `None` 。如果提供该参数的话,长度必须为 `num_classes` 。数据类型为float32或float64。
- **reduction** (string, 可选): - 指定应用于输出结果的计算方式,可选值有: `none`, `mean`, `sum` 。默认为 `mean` ,计算 `mini-batch` loss均值。设置为 `sum` 时,计算 `mini-batch` loss的总和。设置为 `none` 时,则返回loss Tensor。数据类型为string。
- **ignore_index** (int64, 可选): - 指定一个忽略的标签值,此标签值不参与计算。默认值为-100。数据类型为int64。
返回:返回存储表示 `negative log likihood loss` 的损失值。
返回类型:Variable
**代码示例**
.. code-block:: python
# declarative mode
import paddle.fluid as fluid
import numpy as np
import paddle
input_np = np.random.random(size=(10, 10)).astype(np.float32)
label_np = np.random.randint(0, 10, size=(10,)).astype(np.int64)
prog = fluid.Program()
startup_prog = fluid.Program()
place = fluid.CPUPlace()
with fluid.program_guard(prog, startup_prog):
input = fluid.data(name='input', shape=[10, 10], dtype='float32')
label = fluid.data(name='label', shape=[10], dtype='int64')
nll_loss = fluid.dygraph.NLLLoss()
res = nll_loss(input, label)
exe = fluid.Executor(place)
static_result = exe.run(
prog,
feed={"input": input_np,
"label": label_np},
fetch_list=[res])
print(static_result)
# imperative mode
import paddle.fluid.dygraph as dg
with dg.guard(place) as g:
input = dg.to_variable(input_np)
label = dg.to_variable(label_np)
output = nll_loss(input, label)
print(output.numpy())
ProgramTranslator
-------------------------------
**版本升级,文档正在开发中**
declarative
-------------------------------
**版本升级,文档正在开发中**
=======================
paddle.framework
=======================
.. toctree::
:maxdepth: 1
framework_cn/get_default_dtype_cn.rst
framework_cn/manual_seed_cn.rst
framework_cn/set_default_dtype_cn.rst
get
-------------------------------
**版本升级,文档正在开发中**
manual
-------------------------------
**版本升级,文档正在开发中**
set
-------------------------------
**版本升级,文档正在开发中**
......@@ -6,6 +6,9 @@ API Reference
:maxdepth: 1
../api_guides/index_cn.rst
framework_cn.rst
nn_cn.rst
tensor_cn.rst
fluid_cn.rst
api_tree_cn.rst
backward_cn.rst
......@@ -21,5 +24,6 @@ API Reference
optimizer_cn.rst
profiler_cn.rst
regularizer_cn.rst
tensor_cn.rst
transpiler_cn.rst
unique_name_cn.rst
......@@ -16,13 +16,9 @@ fluid.layers
layers_cn/adaptive_pool2d_cn.rst
layers_cn/adaptive_pool3d_cn.rst
layers_cn/add_position_encoding_cn.rst
layers_cn/addcmul_cn.rst
layers_cn/addmm_cn.rst
layers_cn/affine_channel_cn.rst
layers_cn/affine_grid_cn.rst
layers_cn/allclose_cn.rst
layers_cn/anchor_generator_cn.rst
layers_cn/arange_cn.rst
layers_cn/argmax_cn.rst
layers_cn/argmin_cn.rst
layers_cn/argsort_cn.rst
......@@ -39,7 +35,6 @@ fluid.layers
layers_cn/beam_search_decode_cn.rst
layers_cn/bilinear_tensor_product_cn.rst
layers_cn/bipartite_match_cn.rst
layers_cn/bmm_cn.rst
layers_cn/box_clip_cn.rst
layers_cn/box_coder_cn.rst
layers_cn/box_decoder_and_assign_cn.rst
......@@ -52,7 +47,6 @@ fluid.layers
layers_cn/ceil_cn.rst
layers_cn/center_loss_cn.rst
layers_cn/chunk_eval_cn.rst
layers_cn/clamp_cn.rst
layers_cn/clip_by_norm_cn.rst
layers_cn/clip_cn.rst
layers_cn/collect_fpn_proposals_cn.rst
......@@ -74,7 +68,6 @@ fluid.layers
layers_cn/crf_decoding_cn.rst
layers_cn/crop_cn.rst
layers_cn/crop_tensor_cn.rst
layers_cn/cross_cn.rst
layers_cn/cross_entropy_cn.rst
layers_cn/ctc_greedy_decoder_cn.rst
layers_cn/cumsum_cn.rst
......@@ -85,11 +78,8 @@ fluid.layers
layers_cn/density_prior_box_cn.rst
layers_cn/detection_output_cn.rst
layers_cn/diag_cn.rst
layers_cn/diag_embed_cn.rst
layers_cn/dice_loss_cn.rst
layers_cn/dist_cn.rst
layers_cn/distribute_fpn_proposals_cn.rst
layers_cn/dot_cn.rst
layers_cn/double_buffer_cn.rst
layers_cn/dropout_cn.rst
layers_cn/dynamic_gru_cn.rst
......@@ -101,7 +91,6 @@ fluid.layers
layers_cn/edit_distance_cn.rst
layers_cn/elementwise_add_cn.rst
layers_cn/elementwise_div_cn.rst
layers_cn/elementwise_equal_cn.rst
layers_cn/elementwise_floordiv_cn.rst
layers_cn/elementwise_max_cn.rst
layers_cn/elementwise_min_cn.rst
......@@ -122,11 +111,8 @@ fluid.layers
layers_cn/fill_constant_cn.rst
layers_cn/filter_by_instag_cn.rst
layers_cn/flatten_cn.rst
layers_cn/flip_cn.rst
layers_cn/floor_cn.rst
layers_cn/fsp_matrix_cn.rst
layers_cn/full_cn.rst
layers_cn/full_like_cn.rst
layers_cn/gather_cn.rst
layers_cn/gather_nd_cn.rst
layers_cn/gather_tree_cn.rst
......@@ -156,14 +142,11 @@ fluid.layers
layers_cn/image_resize_short_cn.rst
layers_cn/increment_cn.rst
layers_cn/inverse_time_decay_cn.rst
layers_cn/index_select_cn.rst
layers_cn/instance_norm_cn.rst
layers_cn/interpolate_cn.rst
layers_cn/iou_similarity_cn.rst
layers_cn/is_empty_cn.rst
layers_cn/isfinite_cn.rst
layers_cn/kldiv_loss_cn.rst
layers_cn/kron_cn.rst
layers_cn/l2_normalize_cn.rst
layers_cn/label_smooth_cn.rst
layers_cn/layer_norm_cn.rst
......@@ -177,15 +160,12 @@ fluid.layers
layers_cn/lod_append_cn.rst
layers_cn/lod_reset_cn.rst
layers_cn/log_cn.rst
layers_cn/log1p_cn.rst
layers_cn/log_loss_cn.rst
layers_cn/log_softmax_cn.rst
layers_cn/logical_and_cn.rst
layers_cn/logical_not_cn.rst
layers_cn/logical_or_cn.rst
layers_cn/logical_xor_cn.rst
layers_cn/logsigmoid_cn.rst
layers_cn/logsumexp_cn.rst
layers_cn/lrn_cn.rst
layers_cn/lstm_cn.rst
layers_cn/lstm_unit_cn.rst
......@@ -197,7 +177,6 @@ fluid.layers
layers_cn/mean_cn.rst
layers_cn/mean_iou_cn.rst
layers_cn/merge_selected_rows_cn.rst
layers_cn/meshgrid_cn.rst
layers_cn/mse_loss_cn.rst
layers_cn/mul_cn.rst
layers_cn/multi_box_head_cn.rst
......@@ -207,7 +186,6 @@ fluid.layers
layers_cn/natural_exp_decay_cn.rst
layers_cn/nce_cn.rst
layers_cn/noam_decay_cn.rst
layers_cn/nonzero_cn.rst
layers_cn/Normal_cn.rst
layers_cn/not_equal_cn.rst
layers_cn/npair_loss_cn.rst
......@@ -232,10 +210,8 @@ fluid.layers
layers_cn/py_func_cn.rst
layers_cn/py_reader_cn.rst
layers_cn/randint_cn.rst
layers_cn/randn_cn.rst
layers_cn/random_crop_cn.rst
layers_cn/range_cn.rst
layers_cn/randperm_cn.rst
layers_cn/rank_cn.rst
layers_cn/rank_loss_cn.rst
layers_cn/read_file_cn.rst
......@@ -261,7 +237,6 @@ fluid.layers
layers_cn/roi_align_cn.rst
layers_cn/roi_perspective_transform_cn.rst
layers_cn/roi_pool_cn.rst
layers_cn/roll_cn.rst
layers_cn/round_cn.rst
layers_cn/row_conv_cn.rst
layers_cn/rpn_target_assign_cn.rst
......@@ -325,7 +300,6 @@ fluid.layers
layers_cn/swish_cn.rst
layers_cn/Switch_cn.rst
layers_cn/switch_case_cn.rst
layers_cn/t_cn.rst
layers_cn/tanh_cn.rst
layers_cn/tanh_shrink_cn.rst
layers_cn/target_assign_cn.rst
......@@ -334,10 +308,7 @@ fluid.layers
layers_cn/tensor_array_to_tensor_cn.rst
layers_cn/thresholded_relu_cn.rst
layers_cn/topk_cn.rst
layers_cn/trace_cn.rst
layers_cn/transpose_cn.rst
layers_cn/tril_cn.rst
layers_cn/triu_cn.rst
layers_cn/unfold_cn.rst
layers_cn/Uniform_cn.rst
layers_cn/uniform_random_cn.rst
......
.. _cn_api_fluid_layers_randint:
randint
-------------------------------
**版本升级,文档正在开发中**
.. py:function:: paddle.fluid.layers.randint(low, high=None, shape=None, out=None, dtype=None, device=None, stop_gradient=False, seed=0, name=None)
该OP使用从区间[low,high)内均匀分布采样的随机整数初始化一个Tensor。当high为None时(默认),均匀采样的区间为[0,low)。
参数:
- **low** (int)-要生成的随机值范围的下限,low包含在范围中。当high为None时,均匀采样的区间为[0,low)。
- **high** (int,可选)-要生成的随机值范围的上限,high不包含在范围中。默认值为None。
- **shape** (list|tuple|Variable,可选)-输出Tensor的维度,shape类型支持list,tuple,Variable。如果shape类型是list或者tuple,它的元素可以是整数或者形状为[1]的Tensor,其中整数的数据类型为int,Tensor的数据类型为int32或int64。如果shape的类型是Variable,则是1D的Tensor,Tensor的数据类型为int32或int64。如果shape为None,则会将shape设置为[1]。默认值为None。
- **out** (Variable,可选)-用于存储创建的Tensor,可以是程序中已经创建的任何Variable。默认值为None,此时将创建新的Variable来保存输出结果。
- **dtype** (np.dtype|core.VarDesc.VarType|str,可选)- 输出Tensor的数据类型,支持数据类型为int32,int64。如果dtype为None,则会将dtype设置为int64。默认值为None。
- **device** (str, 可选)-指定在GPU或CPU上创建Tensor。如果device为None,则将选择运行Paddle程序的设备,默认为None。
- **stop_gradient** (bool,可选)-指定是否停止梯度计算,默认值为False。
- **seed** (int,可选)-随机种子,用于生成样本。0表示使用系统生成的种子。注意如果种子不为0,该操作符每次都生成同样的随机数。默认为 0。
- **name** (str,可选)-具体用法请参见:ref:`api_guide_Name` ,一般无需设置,默认值为None。
返回:表示一个随机初始化结果的Tensor,该Tensor的数据类型由dtype参数决定,该Tensor的维度由shape参数决定。
返回类型:Variable
抛出异常:
- :code:`TypeError`: shape的类型应该是list、tuple 或 Variable。
- :code:`TypeError`: dtype的类型应该是int32或int64。
- :code:`ValueError`: 该OP的high必须大于low(high为None时,则会先将high设置为low,将low设置为0,再判断low和high的大小关系)。
**代码示例**:
.. code-block:: python
import paddle.fluid as fluid
# example 1:
# attr shape is a list which doesn't contain tensor Variable.
result_1 = fluid.layers.randint(low=-5, high=5, shape=[3, 4], dtype="int64")
# example 2:
# attr shape is a list which contains tensor Variable.
dim_1 = fluid.layers.fill_constant([1],"int64",3)
dim_2 = fluid.layers.fill_constant([1],"int32",5)
result_2 = fluid.layers.randint(low=-5, high=5, shape=[dim_1, dim_2], dtype="int32")
# example 3:
# attr shape is a Variable, the data type must be int64 or int32.
var_shape = fluid.data(name='var_shape', shape=[2], dtype="int64")
result_3 = fluid.layers.randint(low=-5, high=5, shape=var_shape, dtype="int32")
var_shape_int32 = fluid.data(name='var_shape_int32', shape=[2], dtype="int32")
result_4 = fluid.layers.randint(low=-5, high=5, shape=var_shape_int32, dtype="int64")
# example 4:
# Input only one parameter
# low=0, high=10, shape=[1], dtype='int64'
result_4 = fluid.layers.randint(10)
trace
-------------------------------
**版本升级,文档正在开发中**
=======================
paddle.nn
=======================
.. toctree::
:maxdepth: 1
nn_cn/Conv1D_cn.rst
nn_cn/Conv2D_cn.rst
nn_cn/diag_embed_cn.rst
nn_cn/interpolate_cn.rst
nn_cn/Linear_cn.rst
nn_cn/log_softmax_cn.rst
nn_cn/ReLU_cn.rst
nn_cn/Upsample_cn.rst
nn_cn/activation_cn.rst
nn_cn/loss_cn.rst
Conv1D
-------------------------------
**版本升级,文档正在开发中**
Conv2D
-------------------------------
**版本升级,文档正在开发中**
Linear
-------------------------------
**版本升级,文档正在开发中**
ReLU
-------------------------------
**版本升级,文档正在开发中**
Upsample
-------------------------------
**版本升级,文档正在开发中**
=======================
activation
=======================
.. toctree::
:maxdepth: 1
activation_cn/Sigmoid_cn.rst
Sigmoid
-------------------------------
**版本升级,文档正在开发中**
=======================
loss
=======================
.. toctree::
:maxdepth: 1
loss_cn/BCELoss_cn.rst
loss_cn/CrossEntropyLoss_cn.rst
loss_cn/L1Loss_cn.rst
loss_cn/MSELoss_cn.rst
loss_cn/NLLLoss_cn.rst
InstanceNorm
CrossEntropyLoss
-------------------------------
**版本升级,文档正在开发中**
L1Loss
-------------------------------
**版本升级,文档正在开发中**
NLLLoss
-------------------------------
**版本升级,文档正在开发中**
.. _cn_api_tensor_add:
add
-------------------------------
.. py:function:: paddle.add(x, y, alpha=1, out=None, name=None)
该OP是逐元素相加算子,输入 ``x`` 与输入 ``y`` 逐元素相加,并将各个位置的输出元素保存到返回结果中。
等式为:
.. math::
Out = X + Y
- :math:`X` :多维Tensor。
- :math:`Y` :维度必须小于等于X维度的Tensor。
对于这个运算算子有2种情况:
1. :math:`Y` 的 ``shape`` 与 :math:`X` 相同。
2. :math:`Y` 的 ``shape`` 是 :math:`X` 的连续子序列。
对于情况2:
1. 用 :math:`Y` 匹配 :math:`X` 的形状(shape),其中 ``axis`` 是 :math:`Y` 在 :math:`X` 上的起始维度的位置。
2. 如果 ``axis`` 为-1(默认值),则 :math:`axis= rank(X)-rank(Y)` 。
3. 考虑到子序列, :math:`Y` 的大小为1的尾部维度将被忽略,例如shape(Y)=(2,1)=>(2)。
例如:
.. code-block:: text
shape(X) = (2, 3, 4, 5), shape(Y) = (,)
shape(X) = (2, 3, 4, 5), shape(Y) = (5,)
shape(X) = (2, 3, 4, 5), shape(Y) = (4, 5), with axis=-1(default) or axis=2
shape(X) = (2, 3, 4, 5), shape(Y) = (3, 4), with axis=1
shape(X) = (2, 3, 4, 5), shape(Y) = (2), with axis=0
shape(X) = (2, 3, 4, 5), shape(Y) = (2, 1), with axis=0
参数:
- **x** (Variable)- 多维 ``Tensor`` 或 ``LoDTensor`` 。数据类型为 ``float32`` 、 ``float64`` 、 ``int32`` 或 ``int64``。
- **y** (Variable)- 多维 ``Tensor`` 或 ``LoDTensor`` 。数据类型为 ``float32`` 、 ``float64`` 、 ``int32`` 或 ``int64``。
- **alpha** (int|float,可选)- 输入y的缩放因子。默认值为1. 如果alpha不为1,本api计算公式变为 :math:`Out = X + alpha * Y`
- **out** (Variable,可选)- 指定存储运算结果的 ``Tensor`` 。如果设置为None或者不设置,将创建新的 ``Tensor`` 存储运算结果,默认值为None。
- **name** (str,可选)- 输出的名字。默认值为None。该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` 。
返回: 多维 ``Tensor`` 或 ``LoDTensor`` ,维度和数据类型都与 ``x`` 相同。
返回类型: Variable
**代码示例 1**
.. code-block:: python
import paddle
import paddle.fluid as fluid
import numpy as np
def gen_data():
return {
"x": np.array([2, 3, 4]).astype('float32'),
"y": np.array([1, 5, 2]).astype('float32')
}
x = fluid.data(name="x", shape=[3], dtype='float32')
y = fluid.data(name="y", shape=[3], dtype='float32')
z1 = paddle.add(x, y)
z2 = paddle.add(x, y, alpha=10)
# z = x + y
place = fluid.CPUPlace()
exe = fluid.Executor(place)
z_value = exe.run(feed=gen_data(),
fetch_list=[z1.name, z2.name])
print(z_value[0]) # [3., 8., 6.]
print(z_value[1]) # [12. 53. 24.]
**代码示例 2**
.. code-block:: python
import paddle
import paddle.fluid as fluid
import numpy as np
def gen_data():
return {
"x": np.ones((2, 3, 4, 5)).astype('float32'),
"y": np.zeros((4, 5)).astype('float32')
}
x = fluid.data(name="x", shape=[2, 3, 4, 5], dtype='float32')
y = fluid.data(name="y", shape=[4, 5], dtype='float32')
z = paddle.add(x, y, name='z')
# z = x + y
place = fluid.CPUPlace()
exe = fluid.Executor(place)
z_value = exe.run(feed=gen_data(),
fetch_list=[z.name])
print(z_value[0])
print(z_value[0].shape) # z.shape=[2,3,4,5]
**代码示例 3**
.. code-block:: python
import paddle
import paddle.fluid as fluid
import numpy as np
def gen_data():
return {
"x": np.random.randint(1, 5, size=[2, 3, 4, 5]).astype('float32'),
"y": np.random.randint(1, 5, size=[5]).astype('float32')
}
x = fluid.data(name="x", shape=[2,3,4,5], dtype='float32')
y = fluid.data(name="y", shape=[5], dtype='float32')
z = paddle.add(x, y)
# z = x / y
place = fluid.CPUPlace()
exe = fluid.Executor(place)
z_value = exe.run(feed=gen_data(),
fetch_list=[z.name])
print(z_value[0])
print(z_value[0].shape) # z.shape=[2,3,4,5]
**代码示例 4**
.. code-block:: python
import paddle
import paddle.fluid as fluid
import numpy as np
x = fluid.data(name="x", shape=[3], dtype="float32")
y = fluid.data(name='y', shape=[3], dtype='float32')
output = fluid.data(name="output", shape=[3], dtype="float32")
z = paddle.add(x, y, out=output)
place = fluid.CPUPlace()
exe = fluid.Executor(place)
data1 = np.array([2, 3, 4], dtype='float32')
data2 = np.array([1, 5, 2], dtype='float32')
z_value = exe.run(feed={'x': data1,
'y': data2},
fetch_list=[z])
print(z_value[0]) # [3. 8. 6.]
**代码示例 5(动态图)**
.. code-block:: python
import paddle
import paddle.fluid as fluid
import numpy as np
with fluid.dygraph.guard():
np_x = np.array([2, 3, 4]).astype('float64')
np_y = np.array([1, 5, 2]).astype('float64')
x = fluid.dygraph.to_variable(np_x)
y = fluid.dygraph.to_variable(np_y)
z = paddle.add(x, y, alpha=-0.5)
np_z = z.numpy()
print(np_z) # [1.5, 0.5, 3. ]
......@@ -3,7 +3,7 @@
addcmul
-------------------------------
.. py:function:: paddle.fluid.layers.addcmul(input, tensor1, tensor2, value=1.0, out=None, name=None)
.. py:function:: paddle.addcmul(input, tensor1, tensor2, value=1.0, out=None, name=None)
计算tensor1和tensor2的逐元素乘积,然后将结果乘以标量value,再加到input上输出。其中input, tensor1, tensor2的维度必须是可广播的。
......@@ -33,5 +33,5 @@ addcmul
input = fluid.data(name='input', dtype='float32', shape=[3, 4])
tensor1 = fluid.data(name='tenosr1', dtype='float32', shape=[1, 4])
tensor2 = fluid.data(name='tensor2', dtype='float32', shape=[3, 4])
data = fluid.layers.addcmul(input, tensor1, tensor2, value=1.0)
data = paddle.addcmul(input, tensor1, tensor2, value=1.0)
......@@ -3,7 +3,7 @@
arange
-------------------------------
.. py:function:: paddle.fluid.layers.arange(start, end, step=1, dtype=None, name=None)
.. py:function:: paddle.tensor.arange(start, end, step=1, dtype=None, name=None)
该API根据step均匀分隔给定数值区间[start, end),并返回该分隔结果。
......@@ -24,6 +24,6 @@ arange
import paddle
import paddle.fluid as fluid
with fluid.dygraph.guard():
x = fluid.layers.arange(0, 6, 2)
x = paddle.arange(0, 6, 2)
# x: [0, 2, 4]
# x dtype: float32
.. _cn_api_tensor_argmax:
argmax
-------------------------------
.. py:function:: paddle.argmax(input, axis=None, dtype=None, out=None, keepdims=False, name=None)
该OP沿 ``axis`` 计算输入 ``input`` 的最大元素的索引。
参数:
- **input** (Variable) - 输入的多维 ``Tensor`` ,支持的数据类型:float32、float64、int8、int16、int32、int64。
- **axis** (int,可选) - 指定对输入Tensor进行运算的轴, ``axis`` 的有效范围是[-R, R),R是输入 ``input`` 的Rank, ``axis`` -R与绝对值相同的R等价。默认值为0。
- **dtype** (np.dtype|core.VarDesc.VarType|str)- 输出Tensor的数据类型,可选值为int32,int64,默认值为None,将返回int64类型的结果。
- **out** (Variable, 可选) – 指定存储运算结果的Tensor。如果设置为None或者不设置,将创建新的Tensor存储运算结果,默认值为None。
- **keepdims** (bool,可选)- 是否保留进行max index操作的维度,默认值为False。
- **name** (str,可选) – 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。
返回: ``Tensor`` ,数据类型int64
返回类型:Variable
**代码示例**:
.. code-block:: python
import paddle
import paddle.fluid as fluid
import numpy as np
in1 = np.array([[[5,8,9,5],
[0,0,1,7],
[6,9,2,4]],
[[5,2,4,2],
[4,7,7,9],
[1,7,0,6]]])
with fluid.dygraph.guard():
x = fluid.dygraph.to_variable(in1)
out1 = paddle.argmax(input=x, axis=-1)
out2 = paddle.argmax(input=x, axis=0)
out3 = paddle.argmax(input=x, axis=1)
out4 = paddle.argmax(input=x, axis=2)
out5 = paddle.argmax(input=x, axis=2, keepdims=True)
print(out1.numpy())
# [[2 3 1]
# [0 3 1]]
print(out2.numpy())
# [[0 0 0 0]
# [1 1 1 1]
# [0 0 0 1]]
print(out3.numpy())
# [[2 2 0 1]
# [0 1 1 1]]
print(out4.numpy())
# [[2 3 1]
# [0 3 1]]
print(out5.numpy())
#array([[[2],
# [3],
# [1]],
# [[0],
# [3],
# [1]]])
.. _cn_api_tensor_atan:
atan
-------------------------------
.. py:function:: paddle.atan(x, name=None, out=None)
arctanh 激活函数。
.. math::
out = tanh^{-1}(x)
参数:
- **x(Variable)** - atan的输入Tensor,数据类型为 float32 或 float64
- **name** (str|None) – 具体用法请参见 :ref:`cn_api_guide_Name` ,一般无需设置,默认值为None。
- **out** (Variable, 可选) – 指定存储运算结果的Tensor。如果设置为None或者不设置,将创建新的Tensor存储运算结果,默认值为None。
返回:返回类型为Variable(Tensor|LoDTensor), 数据类型同输入一致。
**代码示例**:
.. code-block:: python
import numpy as np
import paddle
import paddle.fluid as fluid
inputs = fluid.layers.data(name="x", shape = [3], dtype='float32')
output = paddle.atan(inputs)
exe = fluid.Executor(fluid.CPUPlace())
exe.run(fluid.default_startup_program())
img = np.array([-0.8183, 0.4912, -0.6444, 0.0371]).astype(np.float32)
res = exe.run(fluid.default_main_program(), feed={'x':img}, fetch_list=[output])
print(res)
#[array([-0.6858003, 0.45658287, -0.5724284, 0.03708299], dtype=float32)]
......@@ -3,7 +3,7 @@
bmm
-------------------------------
.. py:function:: paddle.fluid.layers.bmm(x, y, name=None):
.. py:function:: paddle.tensor.bmm(x, y, name=None):
对输入x及输入y进行矩阵相乘。
......@@ -38,7 +38,7 @@ bmm
with fluid.dygraph.guard():
x = fluid.dygraph.to_variable(input1)
y = fluid.dygraph.to_variable(input2)
out = fluid.layers.bmm(x, y)
out = paddle.bmm(x, y)
#output size: (2, 2, 2)
#output value:
#[[[6.0, 6.0],[12.0, 12.0]],[[45.0, 45.0],[60.0, 60.0]]]
......
cholesky
-------------------------------
**版本升级,文档正在开发中**
......@@ -3,7 +3,7 @@
clamp
-------------------------------
.. py:function:: paddle.fluid.layers.clamp(input, min=None, max=None, output=None, name=None)
.. py:function:: paddle.clamp(input, min=None, max=None, output=None, name=None)
该OP将输入的所有元素进行剪裁,使得输出元素限制在[min, max]内,具体公式如下:
......@@ -34,8 +34,8 @@ clamp
[4.5,6.4]]).astype('float32')
with fluid.dygraph.guard():
x1 = fluid.dygraph.to_variable(in1)
out1 = fluid.layers.clamp(x1, min=3.5, max=5.0)
out2 = fluid.layers.clamp(x1, min=2.5)
out1 = paddle.tensor.clamp(x1, min=3.5, max=5.0)
out2 = paddle.tensor.clamp(x1, min=2.5)
print(out1.numpy())
# [[3.5, 3.5]
# [4.5, 5.0]]
......
concat
-------------------------------
**版本升级,文档正在开发中**
......@@ -3,7 +3,7 @@
cross
-------------------------------
.. py:function:: paddle.fluid.layers.cross(input, other, dim=None)
.. py:function:: paddle.cross(input, other, dim=None)
该OP返回在 ``dim`` 维度上,两个张量 ``input`` 和 ``other`` 的向量积(叉积)。 ``input`` 和 ``other`` 必须有相同的形状,
且指定的 ``dim`` 维上 ``size`` 必须为3,如果 ``dim`` 未指定,默认选取第一个 ``size`` 等于3的维度。
......@@ -34,12 +34,12 @@ cross
with fluid.dygraph.guard():
x = fluid.dygraph.to_variable(data_x)
y = fluid.dygraph.to_variable(data_y)
out_z1 = fluid.layers.cross(x, y)
out_z1 = paddle.cross(x, y)
print(out_z1.numpy())
#[[-1. -1. -1.]
# [ 2. 2. 2.]
# [-1. -1. -1.]]
out_z2 = fluid.layers.cross(x, y, dim=1)
out_z2 = paddle.cross(x, y, dim=1)
print(out_z2.numpy())
#[[0. 0. 0.]
# [0. 0. 0.]
......
......@@ -3,7 +3,7 @@
dist
-------------------------------
.. py:function:: paddle.fluid.layers.linalg.dist(x, y, p=2)
.. py:function:: paddle.tensor.linalg.dist(x, y, p=2)
该OP用于计算 `(x-y)` 的 p 范数(p-norm),需要注意这不是严格意义上的范数,仅作为距离的度量。输入 `x` 和 `y` 的形状(shape)必须是可广播的(broadcastable)。其含义如下,详情请参考 `numpy的广播概念 <https://docs.scipy.org/doc/numpy/user/basics.broadcasting.html>`_ :
......@@ -65,11 +65,11 @@ z (4-D Tensor): 8 x 7 x 6 x 5
with fluid.dygraph.guard():
x = fluid.dygraph.to_variable(np.array([[3, 3],[3, 3]]).astype(np.float32))
y = fluid.dygraph.to_variable(np.array([[3, 3],[3, 1]]).astype(np.float32))
out = fluid.layers.dist(x, y, 0)
out = paddle.dist(x, y, 0)
print(out.numpy()) # out = [1.]
out = fluid.layers.dist(x, y, 2)
out = paddle.dist(x, y, 2)
print(out.numpy()) # out = [2.]
out = fluid.layers.dist(x, y, float("inf"))
out = paddle.dist(x, y, float("inf"))
print(out.numpy()) # out = [2.]
out = fluid.layers.dist(x, y, float("-inf"))
out = paddle.dist(x, y, float("-inf"))
print(out.numpy()) # out = [0.]
.. _cn_api_tensor_div:
div
-------------------------------
.. py:function:: paddle.div(x, y, out=None, name=None)
该OP是逐元素相除算子,输入 ``x`` 与输入 ``y`` 逐元素相除,并将各个位置的输出元素保存到返回结果中。
等式是:
.. math::
Out = X / Y
- :math:`X` :多维Tensor。
- :math:`Y` :维度必须小于等于X维度的Tensor。
对于这个运算算子有2种情况:
1. :math:`Y` 的 ``shape`` 与 :math:`X` 相同。
2. :math:`Y` 的 ``shape`` 是 :math:`X` 的连续子序列。
对于情况2:
1. 用 :math:`Y` 匹配 :math:`X` 的形状(shape),其中 ``axis`` 是 :math:`Y` 在 :math:`X` 上的起始维度的位置。
2. 如果 ``axis`` 为-1(默认值),则 :math:`axis= rank(X)-rank(Y)` 。
3. 考虑到子序列, :math:`Y` 的大小为1的尾部维度将被忽略,例如shape(Y)=(2,1)=>(2)。
例如:
.. code-block:: text
shape(X) = (2, 3, 4, 5), shape(Y) = (,)
shape(X) = (2, 3, 4, 5), shape(Y) = (5,)
shape(X) = (2, 3, 4, 5), shape(Y) = (4, 5), with axis=-1(default) or axis=2
shape(X) = (2, 3, 4, 5), shape(Y) = (3, 4), with axis=1
shape(X) = (2, 3, 4, 5), shape(Y) = (2), with axis=0
shape(X) = (2, 3, 4, 5), shape(Y) = (2, 1), with axis=0
参数:
- **x** (Variable)- 多维 ``Tensor`` 或 ``LoDTensor`` 。数据类型为 ``float32`` 、 ``float64`` 、 ``int32`` 或 ``int64``。
- **y** (Variable)- 多维 ``Tensor`` 或 ``LoDTensor`` 。数据类型为 ``float32`` 、 ``float64`` 、 ``int32`` 或 ``int64``。
- **out** (Variable,可选)- 指定存储运算结果的 ``Tensor`` 。如果设置为None或者不设置,将创建新的 ``Tensor`` 存储运算结果,默认值为None。
- **name** (str,可选)- 输出的名字。默认值为None。该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` 。
返回: 多维 ``Tensor`` 或 ``LoDTensor`` , 维度和数据类型都与 ``x`` 相同。
返回类型: Variable
**代码示例 1**
.. code-block:: python
import paddle
import paddle.fluid as fluid
import numpy as np
def gen_data():
return {
"x": np.array([2, 3, 4]).astype('float32'),
"y": np.array([1, 5, 2]).astype('float32')
}
x = fluid.data(name="x", shape=[3], dtype='float32')
y = fluid.data(name="y", shape=[3], dtype='float32')
z = paddle.div(x, y)
# z = x / y
place = fluid.CPUPlace()
exe = fluid.Executor(place)
z_value = exe.run(feed=gen_data(),
fetch_list=[z.name])
print(z_value) # [2., 0.6, 2.]
**代码示例 2**
.. code-block:: python
import paddle
import paddle.fluid as fluid
import numpy as np
def gen_data():
return {
"x": np.ones((2, 3, 4, 5)).astype('float32'),
"y": np.zeros((4, 5)).astype('float32')
}
x = fluid.data(name="x", shape=[2, 3, 4, 5], dtype='float32')
y = fluid.data(name="y", shape=[4, 5], dtype='float32')
z = paddle.div(x, y, name='z')
# z = x / y
place = fluid.CPUPlace()
exe = fluid.Executor(place)
z_value = exe.run(feed=gen_data(),
fetch_list=[z.name])
print(z_value[0])
print(z_value[0].shape) # z.shape=[2,3,4,5]
**代码示例 3**
.. code-block:: python
import paddle
import paddle.fluid as fluid
import numpy as np
def gen_data():
return {
"x": np.random.randint(1, 5, size=[2, 3, 4, 5]).astype('float32'),
"y": np.random.randint(1, 5, size=[5]).astype('float32')
}
x = fluid.data(name="x", shape=[2,3,4,5], dtype='float32')
y = fluid.data(name="y", shape=[5], dtype='float32')
output = fluid.data(name="output", shape=[2,3,4,5], dtype="float32")
z = paddle.div(x, y, out=output)
# z = x / y
place = fluid.CPUPlace()
exe = fluid.Executor(place)
z_value = exe.run(feed=gen_data(),
fetch_list=[z.name])
print(z_value[0])
print(z_value[0].shape) # z.shape=[2,3,4,5]
**代码示例 4(动态图)**
.. code-block:: python
import paddle
import paddle.fluid as fluid
import numpy as np
with fluid.dygraph.guard(fluid.CPUPlace()):
np_x = np.array([2, 3, 4]).astype('float64')
np_y = np.array([1, 5, 2]).astype('float64')
x = fluid.dygraph.to_variable(np_x)
y = fluid.dygraph.to_variable(np_y)
z = paddle.div(x, y)
np_z = z.numpy()
print(np_z) # [2., 0.6, 2.]
......@@ -3,7 +3,7 @@
dot
-------------------------------
.. py:function:: paddle.fluid.layers.dot(x, y, name=None)
.. py:function:: paddle.tensor.linalg.dot(x, y, name=None)
该OP计算向量的内积
......@@ -31,7 +31,7 @@ dot
with fluid.dygraph.guard():
x = fluid.dygraph.to_variable(np.random.uniform(0.1, 1, [10]).astype(np.float32))
y = fluid.dygraph.to_variable(np.random.uniform(1, 3, [10]).astype(np.float32))
z = fluid.layers.dot(x, y)
z = paddle.dot(x, y)
print(z.numpy())
einsum
-------------------------------
**版本升级,文档正在开发中**
......@@ -3,7 +3,7 @@
elementwise_equal
-------------------------------
.. py:function:: paddle.fluid.layers.elementwise_equal(x, y, name=None)
.. py:function:: paddle.elementwise_equal(x, y, name=None)
该OP返回 :math:`x==y` 逐元素比较x和y是否相等。
......@@ -26,4 +26,4 @@ elementwise_equal
label = fluid.layers.assign(np.array([3, 3], dtype="int32"))
limit = fluid.layers.assign(np.array([3, 2], dtype="int32"))
out1 = fluid.layers.elementwise_equal(x=label, y=limit) #out1=[True, False]
out1 = paddle.elementwise_equal(x=label, y=limit) #out1=[True, False]
.. _cn_api_tensor_elementwise_sum:
elementwise_sum
-------------------------------
.. py:function:: paddle.elementwise_sum(inputs, name=None)
该OP用于对输入的一至多个Tensor或LoDTensor求和。如果输入的是LoDTensor,输出仅与第一个输入共享LoD信息(序列信息)。
例1:
::
输入:
input.shape = [2, 3]
input = [[1, 2, 3],
[4, 5, 6]]
输出:
output.shape = [2, 3]
output = [[1, 2, 3],
[4, 5, 6]]
例2:
::
输入:
第一个输入:
input1.shape = [2, 3]
input1 = [[1, 2, 3],
[4, 5, 6]]
第二个输入:
input2.shape = [2, 3]
input2 = [[7, 8, 9],
[10, 11, 12]]
输出:
output.shape = [2, 3]
output = [[8, 10, 12],
[14, 16, 18]]
参数:
- **inputs** (Variable|list(Variable)) - 输入的一至多个Variable。如果输入了多个Variable,则不同Variable间的shape和数据类型应保持一致。Variable为多维Tensor或LoDTensor,数据类型支持:float32,float64,int32,int64。
- **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。
返回:对输入 ``inputs`` 中的Variable求和后的结果,shape和数据类型与 ``inputs`` 一致。
返回类型:Variable
**代码示例:**
.. code-block:: python
import paddle
import paddle.fluid as fluid
input0 = fluid.layers.fill_constant(shape=[2, 3], dtype='int64', value=5)
input1 = fluid.layers.fill_constant(shape=[2, 3], dtype='int64', value=3)
sum = paddle.elementwise_sum([input0, input1])
#用户可以通过executor打印出求和的结果
out = fluid.layers.Print(sum, message="the sum of input0 and input1: ")
exe = fluid.Executor(fluid.CPUPlace())
exe.run(fluid.default_main_program())
#打印出的数据为:
1570701754 the sum of input0 and input1: The place is:CPUPlace
Tensor[elementwise_sum_0.tmp_0]
shape: [2,3,]
dtype: l
data: 8,8,8,8,8,8,
#输出了shape为[2,3]的Tensor,与输入的shape一致
#dtype为对应C++数据类型,在不同环境下可能显示值不同,但本质相同
#例如:如果Tensor中数据类型是int64,则对应的C++数据类型为int64_t,所以dtype值为typeid(int64_t).name(),
# 其在MacOS下为'x',linux下为'l',Windows下为'__int64',都表示64位整型变量
equal
-------------------------------
**版本升级,文档正在开发中**
erf
-------------------------------
**版本升级,文档正在开发中**
.. _cn_api_paddle_tensor_eye:
eye
-------------------------------
.. py:function:: paddle.tensor.eye(num_rows, num_columns=None, out=None, dtype='float32', stop_gradient=True, name=None)
该OP用来构建单位矩阵。
参数:
- **num_rows** (int) - 生成单位矩阵的行数,数据类型为非负int32。
- **num_columns** (int) - 生成单位矩阵的列数,数据类型为非负int32。若为None,则默认等于num_rows。
- **out** (Variable, 可选) - 指定算子输出结果的LoDTensor/Tensor,可以是程序中已经创建的任何Variable。默认值为None,此时将创建新的Variable来保存输出结果。
- **dtype** (string, 可选) - 返回张量的数据类型,可为int32,int64,float16,float32,float64。
- **stop_gradient** (bool, 可选) - 是否对此OP停止计算梯度,默认值为False。
- **name** (str, 可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。
返回:shape为 [num_rows, num_columns]的张量。
返回类型:Variable(Tensor|LoDTensor)数据类型为int32,int64,float16,float32,float64的Tensor或者LoDTensor。
**代码示例**:
.. code-block:: python
import paddle
data = paddle.eye(3, dtype='int32') # paddle.eye 等价于 paddle.tensor.eye
# [[1, 0, 0]
# [0, 1, 0]
# [0, 0, 1]]
data = paddle.eye(2, 3, dtype='int32')
# [[1, 0, 0]
# [0, 1, 0]]
......@@ -3,7 +3,7 @@
flip
-------------------------------
.. py:function:: paddle.fluid.layers.flip(input, dims, name=None):
.. py:function:: paddle.flip(input, dims, name=None):
该OP沿指定轴反转n维tensor.
......@@ -45,6 +45,6 @@ flip
img = np.arange(12).reshape((3,2,2)).astype(np.float32)
with fluid.dygraph.guard():
inputs = fluid.dygraph.to_variable(img)
ret = fluid.layers.flip(inputs, [0, 1])
ret = paddle.flip(inputs, [0, 1])
print(ret.numpy()) # [[[10,11][8, 9]],[[6, 7],[4, 5]] [[2, 3],[0, 1]]]
......@@ -3,7 +3,7 @@
full_like
-------------------------------
.. py:function:: paddle.fluid.layers.full_like(input, fill_value, out=None, dtype=None, device=None, stop_gradient=True, name=None)
.. py:function:: paddle.full_like(input, fill_value, out=None, dtype=None, device=None, stop_gradient=True, name=None)
该OP创建一个和input具有相同的形状和数据类型的Tensor,其中元素值均为fill_value。
......@@ -28,7 +28,7 @@ full_like
import paddle.fluid as fluid
import numpy as np
input = fluid.data(name='input', dtype='float32', shape=[2, 3])
output = fluid.layers..full_like(input, 2.0)
output = paddle.full_like(input, 2.0)
exe = fluid.Executor(fluid.CPUPlace())
exe.run(fluid.default_startup_program())
img=np.array([[1, 2, 3], [4, 5, 6]]).astype(np.float32)
......
.. _cn_api_paddle_tensor_gather
gather
-------------------------------
.. py:function:: paddle.tensor.gather(input, index, overwrite=True)
根据索引 index 获取输入(input)的最外层维度的条目,并将它们拼接在一起。
.. math::
Out=X[Index]
**参数**:
- **input** (Variable) - 输入, 秩 ``rank >= 1`` , 支持的数据类型包括 int32、int64、float32、float64 和 uint8 (CPU)、float16(GPU) 。
- **index** (Variable) - 索引,秩 ``rank = 1``, 数据类型为 int32 或 int64。
- **overwrite** (bool) - 具有相同索引时在反向更新梯度的模式。如果为 ``True`` ,则使用覆盖模式更新相同索引的梯度;如果为 ``False`` ,则使用累积模式更新相同索引的梯度。默认值为 ``True`` 。
**返回**:和输入的秩相同的输出张量。
**返回类型**:Variable
**代码示例**:
.. code-block:: python
import paddle
import paddle.fluid as fluid
import numpy as np
with fluid.dygraph.guard():
input_1 = np.array([[1,2,3],[4,5,6],[7,8,9]])
index_1 = np.array([0,1])
input = fluid.dygraph.to_variable(input_1)
index = fluid.dygraph.to_variable(index_1)
output = paddle.fluid.layers.gather(input, index)
# expected output: [[1, 2, 3],[4, 5, 6]]
......@@ -3,7 +3,7 @@
index_select
-------------------------------
.. py:function:: paddle.fluid.layers.index_select(input, index, dim=0)
.. py:function:: paddle.index_select(input, index, dim=0)
该OP沿着指定维度 ``dim`` 对输入 ``input`` 进行索引,取 ``index`` 中指定的相应项,然后返回到一个新的张量。这里 ``index`` 是一个 ``1-D`` 张量。除 ``dim`` 维外,返回的张量其余维度大小同输入 ``input`` , ``dim`` 维大小等于 ``index`` 的大小。
......@@ -31,12 +31,12 @@ index_select
with fluid.dygraph.guard():
x = fluid.dygraph.to_variable(data)
index = fluid.dygraph.to_variable(data_index)
out_z1 = fluid.layers.index_select(x, index)
out_z1 = paddle.index_select(x, index)
print(out_z1.numpy())
#[[1. 2. 3. 4.]
# [5. 6. 7. 8.]
# [5. 6. 7. 8.]]
out_z2 = fluid.layers.index_select(x, index, dim=1)
out_z2 = paddle.index_select(x, index, dim=1)
print(out_z2.numpy())
#[[ 1. 2. 2.]
# [ 5. 6. 6.]
......
inverse
-------------------------------
**版本升级,文档正在开发中**
isnan
-------------------------------
**版本升级,文档正在开发中**
......@@ -3,7 +3,7 @@
kron
-------------------------------
.. py:function:: paddle.fluid.layers.kron(x, y, out=None, name=None)
.. py:function:: paddle.tensor.kron(x, y, out=None, name=None)
Kronecker Product 算子。
......@@ -61,7 +61,7 @@ Kronecker Product 算子。
with dg.guard(place):
a_var = dg.to_variable(a)
b_var = dg.to_variable(b)
c_var = fluid.layers.kron(a_var, b_var)
c_var = paddle.kron(a_var, b_var)
c_np = c_var.numpy()
print(c_np)
......
linspace
-------------------------------
**版本升级,文档正在开发中**
......@@ -3,7 +3,7 @@
log1p
-------------------------------
.. py:function:: paddle.fluid.layers.log1p(x, out=None, name=None)
.. py:function:: paddle.tensor.log1p(x, out=None, name=None)
该OP计算Log1p(加一的自然对数)结果。
......@@ -31,7 +31,7 @@ log1p
import numpy as np
x = fluid.data(name="x", shape=[2,1], dtype="float32")
res = fluid.layers.log1p(x)
res = paddle.log1p(x) # paddle.log1p等价于 paddle.tensor.log1p
# 举例选择CPU计算环境
exe = fluid.Executor(fluid.CPUPlace())
......
......@@ -3,7 +3,7 @@
logsumexp
-------------------------------
.. py:function:: paddle.fluid.layers.logsumexp(x, dim=None, keepdim=False, out=None, name=None)
.. py:function:: paddle.tensor.math.logsumexp(x, dim=None, keepdim=False, out=None, name=None)
该OP对输入Tensor的元素以e为底做指数运算,然后根据指定维度做求和之后取自然对数
......@@ -32,7 +32,7 @@ logsumexp
with fluid.dygraph.guard():
np_x = np.random.uniform(0.1, 1, [10]).astype(np.float32)
x = fluid.dygraph.to_variable(np_x)
print(fluid.layers.logsumexp(x).numpy())
print(paddle.logsumexp(x).numpy())
**代码示例2**
......@@ -45,5 +45,5 @@ logsumexp
with fluid.dygraph.guard():
np_x = np.random.uniform(0.1, 1, [2, 3, 4]).astype(np.float32)
x = fluid.dygraph.to_variable(np_x)
print(fluid.layers.logsumexp(x, dim=1).numpy())
print(fluid.layers.logsumexp(x, dim=[0, 2]).numpy())
print(paddle.logsumexp(x, dim=1).numpy())
print(paddle.logsumexp(x, dim=[0, 2]).numpy())
math
-------------------------------
**版本升级,文档正在开发中**
matmul
-------------------------------
**版本升级,文档正在开发中**
.. _cn_api_paddle_tensor_max:
max
-------------------------------
.. py:function:: paddle.tensor.max(input, dim=None, keep_dim=False, out=None, name=None)
该OP是对指定维度上的Tensor元素求最大值运算,并输出相应的计算结果。等价于 :ref:`cn_api_fluid_layers_reduce_max`
参数:
- **input** (Variable)- 输入变量为多维Tensor或LoDTensor,支持数据类型为float32,float64,int32,int64。
- **dim** (list | int ,可选)- 求最大值运算的维度。如果为None,则计算所有元素的最大值并返回包含单个元素的Tensor变量,否则必须在 :math:`[−rank(input),rank(input)]` 范围内。如果 :math:`dim [i] <0` ,则维度将变为 :math:`rank+dim[i]` ,默认值为None。
- **keep_dim** (bool)- 是否在输出Tensor中保留减小的维度。如 keep_dim 为true,否则结果张量的维度将比输入张量小,默认值为False。
- **out** (Variable, 可选) - 指定算子输出结果的LoDTensor/Tensor,可以是程序中已经创建的任何Variable。默认值为None,此时将创建新的Variable来保存输出结果。
- **name** (str, 可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。
返回: 在指定dim上进行求最大值运算的Tensor,数据类型和输入数据类型一致。
返回类型: 变量(Variable)
**代码示例**
.. code-block:: python
import paddle
import paddle.fluid as fluid
# x是一个Tensor,元素如下:
# [[0.2, 0.3, 0.5, 0.9]
# [0.1, 0.2, 0.6, 0.7]]
# 接下来的示例中,我们在每处函数调用后面都标注出了它的结果张量。
x = fluid.data(name='x', shape=[2, 4], dtype='float32')
# paddle.max 等价于 paddle.tensor.max
paddle.max(x) # [0.9]
paddle.max(x, dim=0) # [0.2, 0.3, 0.6, 0.9]
paddle.max(x, dim=-1) # [0.9, 0.7]
paddle.max(x, dim=1, keep_dim=True) # [[0.9], [0.7]]
# y是一个shape为[2, 2, 2]的Tensor,元素如下:
# [[[1.0, 2.0], [3.0, 4.0]],
# [[5.0, 6.0], [7.0, 8.0]]]
# 接下来的示例中,我们在每处函数调用后面都标注出了它的结果张量。
y = fluid.data(name='y', shape=[2, 2, 2], dtype='float32')
paddle.max(y, dim=[1, 2]) # [4.0, 8.0]
paddle.max(y, dim=[0, 1]) # [7.0, 8.0]
.. _cn_api_paddle_tensor_min:
min
-------------------------------
.. py:function:: paddle.tensor.min(input, dim=None, keep_dim=False, out=None, name=None)
该OP是对指定维度上的Tensor元素求最小值运算,并输出相应的计算结果。等价于 :ref:`cn_api_fluid_layers_reduce_min`
参数:
- **input** (Variable)- 输入变量为多维Tensor或LoDTensor,支持数据类型为float32,float64,int32,int64。
- **dim** (list | int ,可选)- 求最小值运算的维度。如果为None,则计算所有元素的最小值并返回包含单个元素的Tensor变量,否则必须在 :math:`[−rank(input),rank(input)]` 范围内。如果 :math:`dim [i] <0` ,则维度将变为 :math:`rank+dim[i]` ,默认值为None。
- **keep_dim** (bool)- 是否在输出Tensor中保留减小的维度。如 keep_dim 为true,否则结果张量的维度将比输入张量小,默认值为False。
- **out** (Variable, 可选) - 指定算子输出结果的LoDTensor/Tensor,可以是程序中已经创建的任何Variable。默认值为None,此时将创建新的Variable来保存输出结果。
- **name** (str, 可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。
返回: 在指定dim上进行求最小值运算的Tensor,数据类型和输入数据类型一致。
返回类型: 变量(Variable)
**代码示例**
.. code-block:: python
import paddle
import paddle.fluid as fluid
# x是一个Tensor,元素如下:
# [[0.2, 0.3, 0.5, 0.9]
# [0.1, 0.2, 0.6, 0.7]]
# 接下来的示例中,我们在每处函数调用后面都标注出了它的结果张量。
x = fluid.data(name='x', shape=[2, 4], dtype='float32')
# paddle.min 等价于 paddle.tensor.min
paddle.min(x) # [0.1]
paddle.min(x, dim=0) # [0.1, 0.2, 0.5, 0.7]
paddle.min(x, dim=-1) # [0.2, 0.1]
paddle.min(x, dim=1, keep_dim=True) # [[0.2], [0.1]]
# y是一个shape为[2, 2, 2]的Tensor,元素如下:
# [[[1.0, 2.0], [3.0, 4.0]],
# [[5.0, 6.0], [7.0, 8.0]]]
# 接下来的示例中,我们在每处函数调用后面都标注出了它的结果张量。
y = fluid.data(name='y', shape=[2, 2, 2], dtype='float32')
paddle.min(y, dim=[1, 2]) # [1.0, 5.0]
paddle.min(y, dim=[0, 1]) # [1.0, 2.0]
.. _cn_api_tensor_mm:
mm
-------------------------------
.. py:function:: paddle.mm(input, mat2, out=None, name=None)
用于两个输入矩阵的相乘。
两个输入的形状可为任意维度,但当任一输入维度大于3时,两个输入的维度必须相等。
如果原始 Tensor input 或 mat2 的秩为 1 且未转置,则矩阵相乘后的前置或附加维度 1 将移除。
参数:
- **input** (Variable) : 输入变量,类型为 Tensor 或 LoDTensor。
- **mat2** (Variable) : 输入变量,类型为 Tensor 或 LoDTensor。
- **out** (Variable, 可选) – 指定存储运算结果的Tensor。如果设置为None或者不设置,将创建新的Tensor存储运算结果,默认值为None。
- **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。
返回:
- Variable (Tensor / LoDTensor),矩阵相乘后的结果。
返回类型:
- Variable(变量)。
::
* 例 1:
input: [B, ..., M, K], mat2: [B, ..., K, N]
out: [B, ..., M, N]
* 例 2:
input: [B, M, K], mat2: [B, K, N]
out: [B, M, N]
* 例 3:
input: [B, M, K], mat2: [K, N]
out: [B, M, N]
* 例 4:
input: [M, K], mat2: [K, N]
out: [M, N]
* 例 5:
input: [B, M, K], mat2: [K]
out: [B, M]
* 例 6:
input: [K], mat2: [K]
out: [1]
* 例 7:
input: [M], mat2: [N]
out: [M, N]
**代码示例**:
.. code-block:: python
import paddle
import paddle.fluid as fluid
input = fluid.data(name='input', shape=[2, 3], dtype='float32')
mat2 = fluid.data(name='mat2', shape=[3, 2], dtype='float32')
out = paddle.mm(input, mat2) # out shape is [2, 2]
.. _cn_api_tensor_argmax:
mul
-------------------------------
.. py:function:: paddle.mul(x, y, x_num_col_dims=1, y_num_col_dims=1, out=None, name=None)
mul算子
此运算是用于对输入x和y执行矩阵乘法。
公式是:
.. math::
out = x * y
输入x和y都可以携带LoD(详细程度)信息。但输出仅与输入x共享LoD信息。
参数:
- **x** (Variable) - 乘法运算的第一个输入张量Tensor/LoDTensor。
- **y** (Variable) - 乘法运算的第二个输入张量Tensor/LoDTensor。
- **x_num_col_dims** (int,可选) - 默认值1, 可以将具有两个以上维度的张量作为输入。如果输入x是具有多于两个维度的张量,则输入x将先展平为二维矩阵。展平规则是:前 ``num_col_dims`` 将被展平成最终矩阵的第一个维度(矩阵的高度),其余的 rank(x) - num_col_dims 维度被展平成最终矩阵的第二个维度(矩阵的宽度)。结果是展平矩阵的高度等于x的前 ``x_num_col_dims`` 维数的乘积,展平矩阵的宽度等于x的最后一个 rank(x)- ``num_col_dims`` 个剩余维度的维数的乘积。例如,假设x是一个5-D张量,形状为(2,3,4,5,6),并且 ``x_num_col_dims`` 的值为3。 则扁平化后的张量具有的形即为(2x3x4,5x6)=(24,30)。
- **y_num_col_dims** (int,可选) - 默认值1, 可以将具有两个以上维度的张量作为输入。如果输入y是具有多于两个维度的张量,则y将首先展平为二维矩阵。 ``y_num_col_dims`` 属性确定y的展平方式。有关更多详细信息,请参阅 ``x_num_col_dims`` 的注释。
- **out** (Variable, 可选) - 默认值None,如果out不为空,则矩阵乘法运算结果存储在out变量中。
- **name** (str,可选) - 默认值None,输出的名称。该参数供开发人员打印调试信息时使用,具体用法参见 :ref:`api_guide_name`。当out和name同时不为空时,结果输出变量名与out保持一致。
返回:Variable(Tensor)乘法运算输出张量。
返回类型:变量(Variable)。
**代码示例**
.. code-block:: python
import paddle
import paddle.fluid as fluid
dataX = fluid.data(name="dataX", shape=[2, 5], dtype="float32")
dataY = fluid.data(name="dataY", shape=[5, 3], dtype="float32")
res = fluid.data(name="output", shape=[2, 3], dtype="float32")
output = paddle.mul(dataX, dataY,
x_num_col_dims = 1,
y_num_col_dims = 1,
out=res)
......@@ -3,7 +3,7 @@
nonzero
-------------------------------
.. py:function:: paddle.fluid.layers.nonzero(input, as_tuple=False)
.. py:function:: paddle.nonzero(input, as_tuple=False)
该OP返回输入 ``input`` 中非零元素的坐标。如果输入 ``input`` 有 ``n`` 维,共包含 ``z`` 个非零元素,当 ``as_tuple = False`` 时,
返回结果是一个 ``shape`` 等于 ``[z x n]`` 的 ``Tensor`` , 第 ``i`` 行代表输入中第 ``i`` 个非零元素的坐标;当 ``as_tuple = True`` 时,
......@@ -33,12 +33,12 @@ nonzero
x1 = fluid.dygraph.to_variable(data1)
x2 = fluid.dygraph.to_variable(data2)
x3 = fluid.dygraph.to_variable(data3)
out_z1 = fluid.layers.nonzero(x1)
out_z1 = paddle.nonzero(x1)
print(out_z1.numpy())
#[[0 0]
# [1 1]
# [2 2]]
out_z1_tuple = fluid.layers.nonzero(x1, as_tuple=True)
out_z1_tuple = paddle.nonzero(x1, as_tuple=True)
for out in out_z1_tuple:
print(out.numpy())
#[[0]
......@@ -47,19 +47,19 @@ nonzero
#[[0]
# [1]
# [2]]
out_z2 = fluid.layers.nonzero(x2)
out_z2 = paddle.nonzero(x2)
print(out_z2.numpy())
#[[1]
# [3]]
out_z2_tuple = fluid.layers.nonzero(x2, as_tuple=True)
out_z2_tuple = paddle.nonzero(x2, as_tuple=True)
for out in out_z2_tuple:
print(out.numpy())
#[[1]
# [3]]
out_z3 = fluid.layers.nonzero(x3)
out_z3 = paddle.nonzero(x3)
print(out_z3.numpy())
#[]
out_z3_tuple = fluid.layers.nonzero(x3, as_tuple=True)
out_z3_tuple = paddle.nonzero(x3, as_tuple=True)
for out in out_z3_tuple:
print(out.numpy())
#[]
......
.. _cn_api_tensor_norm:
norm
-------------------------------
.. py:function:: paddle.norm(input, p='fro', axis=None, keepdim=False, out=None, name=None):
该OP将计算给定Tensor的矩阵范数(Frobenius 范数)和向量范数(向量1范数、2范数、或者通常的p范数).
参数:
- **input** (Variable) - 输入Tensor。维度为多维,数据类型为float32或float64。
- **p** (float|string, 可选) - 范数的种类。目前支持的值为 `fro`、 `1`、 `2`,和任何正实数p对应的p范数。
- **axis** (int|list, 可选) - 使用范数计算的轴。如果 ``axis`` 为int或者只有一个元素的list,``norm`` API会计算输入Tensor的向量范数。如果axis为包含两个元素的list,API会计算输入Tensor的矩阵范数。 当 ``axis < 0`` 时,实际的计算维度为 rank(input) + axis。
- **keepdim** (bool,可选) - 是否在输出的Tensor中保留和输入一样的维度,默认值为False。当 :attr:`keepdim` 为False时,输出的Tensor会比输入 :attr:`input` 的维度少一些。
- **out** (Variable,可选) - 指定输出的Tensor,默认值为None。out的数据类型必须与输入 ``input`` 一致。
- **name** (str|None) - 该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` 。默认值为None。
返回:在指定axis上进行范数计算的Tensor,与输入input数据类型相同。
返回类型:Variable,与输入input数据类型相同。
抛出异常:
- ``TypeError`` - 当输出 ``out`` 和输入 ``input`` 数据类型不一致时候。
- ``ValueError`` - 当参数 ``p`` 或者 ``axis`` 不合法时。
**代码示例**:
.. code-block:: python
import paddle
import paddle.fluid as fluid
x = fluid.data(name='x', shape=[2, 3, 5], dtype='float64')
# compute frobenius norm along last two dimensions.
out_fro = paddle.norm(x, p='fro', axis=[1,2])
# compute 2-order vector norm along last dimension.
out_pnorm = paddle.norm(x, p=2, axis=-1)
.. _cn_api_tensor_ones:
ones
-------------------------------
.. py:function:: paddle.ones(shape, dtype, out=None, device=None)
该OP创建形状为 ``shape`` 、数据类型为 ``dtype`` 且值全为1的Tensor。
参数:
- **shape** (tuple|list) - 输出Tensor的形状。
- **dtype** (np.dtype|core.VarDesc.VarType|str) - 输出Tensor的数据类型,数据类型必须为float16、float32、float64、int32或int64。
- **out** (Variable, 可选) – 指定存储运算结果的Tensor。如果设置为None或者不设置,将创建新的Tensor存储运算结果,默认值为None。
- **device** (str,可选) – 选择在哪个设备运行该操作,可选值包括None,'cpu'和'gpu'。如果 ``device`` 为None,则将选择运行Paddle程序的设备,默认为None。
返回:值全为1的Tensor,数据类型和 ``dtype`` 定义的类型一致。
返回类型:Variable
**代码示例**:
.. code-block:: python
import paddle
data = paddle.ones(shape=[3, 2], dtype='float32') # [[1., 1.], [1., 1.], [1., 1.]]
data = paddle.ones(shape=[2, 2], dtype='float32', device='cpu') # [[1., 1.], [1., 0.]]
.. _cn_api_tensor_ones_like:
ones_like
-------------------------------
.. py:function:: paddle.ones_like(input, dtype=None, device=None, name=None)
该OP创建一个和input具有相同的形状和数据类型的全1Tensor。
参数:
- **input** (Variable) – 指定输入为一个多维的Tensor,数据类型可以是bool,float32,float64,int32,int64。
- **dtype** (np.dtype|core.VarDesc.VarType|str, 可选)- 输出变量的数据类型。若参数为空,则输出变量的数据类型和输入变量相同,默认值为None。
- **device** (str,可选) – 选择在哪个设备运行该操作,可选值包括None,'cpu'和'gpu'。如果 ``device`` 为None,则将选择运行Paddle程序的设备,默认为None。
- **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。
返回:返回一个存储结果的Tensor。
返回类型:Variable
**代码示例**:
.. code-block:: python
import paddle
import paddle.fluid as fluid
x = fluid.data(name='x', dtype='float32', shape=[3])
data = paddle.ones_like(x) # data=[1.0, 1.0, 1.0]
data1 = paddle.ones_like(input=x, device="gpu") # data1=[1.0, 1.0. 1.0]
.. _cn_api_tensor_argmax:
pow
-------------------------------
.. py:function:: paddle.pow(input, exponent, out=None, name=None):
该OP是指数激活算子:
.. math::
out = x^{exponent}
参数:
- **x** (Variable)- 多维 ``Tensor`` 或 ``LoDTensor`` ,数据类型为 ``float32`` 或 ``float64`` 。
- **exponent** (float32|Variable,可选)- ``float32`` 或形状为[1]的 ``Tensor`` 或 ``LoDTensor``,数据类型为 ``float32``。Pow OP的指数因子。默认值:1.0。
- **out** (Variable, 可选) - 默认值None,如果out不为空,则该运算结果存储在out变量中。
- **name** (str,可选) - 默认值None,输出的名称。该参数供开发人员打印调试信息时使用,具体用法参见 :ref:`api_guide_name`。当out和name同时不为空时,结果输出变量名与out保持一致。
返回:维度与输入 `x` 相同的 ``Tensor`` 或 ``LoDTensor``,数据类型与 ``x`` 相同。
返回类型:Variable。
**代码示例:**
.. code-block:: python
import paddle
import paddle.fluid as fluid
x = fluid.data(name="x", shape=[32,32], dtype="float32")
# 示例1: 参数exponent是个浮点数
res = fluid.data(name="output", shape=[32,32], dtype="float32")
y_1 = paddle.pow(x, 2.0, out=res)
# y_1 is x^{2.0}
# 示例2: 参数exponent是个变量
exponent_tensor = fluid.layers.fill_constant([1], "float32", 3.0)
res = fluid.data(name="output", shape=[32,32], dtype="float32")
y_2 = paddle.pow(x, exponent_tensor, out=res)
# y_2 is x^{3.0}
\ No newline at end of file
rand
-------------------------------
**版本升级,文档正在开发中**
randint
-------------------------------
**版本升级,文档正在开发中**
......@@ -3,7 +3,7 @@
randn
-------------------------------
.. py:function:: paddle.fluid.layers.randn(shape, out=None, dtype=None, device=None, stop_gradient=True, name=None)
.. py:function:: paddle.tensor.random.randn(shape, out=None, dtype=None, device=None, stop_gradient=True, name=None)
该 API 用于生成数据符合标准正态随机分布(均值为 0,方差为 1 的正态随机分布)的 Tensor。
......@@ -26,7 +26,7 @@ randn
# declarative mode
import paddle
import paddle.fluid as fluid
data = fluid.layers.randn([2, 4])
data = paddle.randn([2, 4])
place = fluid.CPUPlace()
exe = fluid.Executor(place)
res, = exe.run(fluid.default_main_program(), feed={}, fetch_list=[data])
......@@ -42,7 +42,7 @@ randn
import paddle.fluid.dygraph as dg
place = fluid.CPUPlace()
with dg.guard(place) as g:
x = fluid.layers.randn([2, 4])
x = paddle.randn([2, 4])
x_np = x.numpy()
print(x_np)
# [[ 1.5149173 -0.26234224 -0.592486 1.4523455 ]
......
......@@ -3,7 +3,7 @@
randperm
-------------------------------
.. py:function:: paddle.fluid.layers.randperm(n, out=None, dtype="int64", device=None, stop_gradient=True, seed=0)
.. py:function:: paddle.tensor.random.randperm(n, out=None, dtype="int64", device=None, stop_gradient=True, seed=0)
该OP返回一个数值在0到n-1、顺序随机的整数排列。
......@@ -31,16 +31,16 @@ randperm
# the random seed in computer, so the output in the next example
# will be change.
with fluid.dygraph.guard():
out_1 = fluid.layers.randperm(6)
out_1 = paddle.randperm(6)
print(out_1.numpy()) # Random permutation, for example [2 4 5 0 3 1]
out_2 = fluid.dygraph.to_variable(
np.array([0, 1, 2, 3])).astype(np.int64)
fluid.layers.randperm(6, out_2)
paddle.randperm(6, out_2)
print(out_2.numpy()) # Random permutation, for example [5 0 2 4 1 3]
out_3 = fluid.layers.randperm(6, dtype="int32", device="cpu")
out_3 = paddle.randperm(6, dtype="int32", device="cpu")
print(out_3.numpy()) # Random permutation, for example [3 1 4 2 5 0]
out_4 = fluid.layers.randperm(6, device="cpu", stop_gradient=True)
out_4 = paddle.randperm(6, device="cpu", stop_gradient=True)
print(out_4.numpy()) # Random permutation, for example [3 1 5 2 0 4]
......@@ -3,7 +3,7 @@
roll
-------------------------------
.. py:function:: paddle.fluid.layers.roll(input, shifts, dims=None):
.. py:function:: paddle.roll(input, shifts, dims=None):
该OP沿着指定维度对输入 ``input`` 进行循环滚动,当元素移动到最后位置时,会从第一个位置重新插入。如果 ``dims`` 为 ``None`` ,则输入在被循环滚动之前,会先展平成 ``1-D Tensor`` ,滚动操作完成后恢复成原来的形状。
......@@ -28,12 +28,12 @@ roll
[7.0, 8.0, 9.0]])
with fluid.dygraph.guard():
x = fluid.dygraph.to_variable(data)
out_z1 = fluid.layers.roll(x, shifts=1)
out_z1 = paddle.roll(x, shifts=1)
print(out_z1.numpy())
#[[9. 1. 2.]
# [3. 4. 5.]
# [6. 7. 8.]]
out_z2 = fluid.layers.roll(x, shifts=1, dims=0)
out_z2 = paddle.roll(x, shifts=1, dims=0)
print(out_z2.numpy())
#[[7. 8. 9.]
# [1. 2. 3.]
......
.. _cn_api_tensor_sin:
sin
-------------------------------
.. py:function:: paddle.sin(x, name=None, out=None)
计算输入的正弦值。
.. math::
out = sin(x)
参数:
- **x** (Variable) - 支持任意维度的Tensor。数据类型为float32,float64或float16。
- **name** (str,可选) – 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。
- **out** (Variable, 可选) – 指定存储运算结果的Tensor。如果设置为None或者不设置,将创建新的Tensor存储运算结果,默认值为None。
返回:返回类型为Variable(Tensor|LoDTensor), 数据类型同输入一致。
**代码示例**:
.. code-block:: python
import numpy as np
import paddle
import paddle.fluid as fluid
inputs = fluid.layers.data(name="x", shape = [3], dtype='float32')
output = paddle.sin(inputs)
exe = fluid.Executor(fluid.CPUPlace())
exe.run(fluid.default_startup_program())
img = np.array([0, 45, 90]).astype(np.float32)
res = exe.run(fluid.default_main_program(), feed={'x':img}, fetch_list=[output])
print(res)
# [array([0. , 0.8509035 , 0.89399666], dtype=float32)]
.. _cn_api_tensor_sort:
sort
-------------------------------
.. py:function:: paddle.sort(input, axis=-1, descending=False, out=None, name=None)
对输入变量沿给定轴进行排序,输出排序好的数据和相应的索引,其维度和输入相同。**默认升序排列,如果需要降序排列设置** ``descending=True`` 。
参数:
- **input** (Variable) - 输入的多维 ``Tensor`` ,支持的数据类型:float32、float64、int16、int32、int64、uint8。
- **axis** (int,可选) - 指定对输入Tensor进行运算的轴, ``axis`` 的有效范围是[-R, R),R是输入 ``x`` 的Rank, ``axis`` 为负时与 ``axis`` +R 等价。默认值为0。
- **descending** (bool,可选) - 指定算法排序的方向。如果设置为True,算法按照降序排序。如果设置为False或者不设置,按照升序排序。默认值为False。
- **out** (Variable, 可选) – 指定存储运算结果的Tensor(与 ``input`` 维度相同、数据类型相同)。如果设置为None或者不设置,将创建新的Tensor存储运算结果,默认值为None。
- **name** (str,可选) – 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。
返回:一组已排序的输出(与 ``input`` 维度相同、数据类型相同)和索引(数据类型为int64)。
返回类型:tuple[Variable]
**代码示例**:
.. code-block:: python
import paddle
import paddle.fluid as fluid
import numpy as np
in1 = np.array([[[5,8,9,5],
[0,0,1,7],
[6,9,2,4]],
[[5,2,4,2],
[4,7,7,9],
[1,7,0,6]]]).astype(np.float32)
with fluid.dygraph.guard():
x = fluid.dygraph.to_variable(in1)
out1 = paddle.sort(input=x, axis=-1) # same as axis==2
out2 = paddle.sort(input=x, axis=0)
out3 = paddle.sort(input=x, axis=1)
print(out1[0].numpy())
# [[[5. 5. 8. 9.]
# [0. 0. 1. 7.]
# [2. 4. 6. 9.]]
# [[2. 2. 4. 5.]
# [4. 7. 7. 9.]
# [0. 1. 6. 7.]]]
print(out1[1].numpy())
# [[[0 3 1 2]
# [0 1 2 3]
# [2 3 0 1]]
# [[1 3 2 0]
# [0 1 2 3]
# [2 0 3 1]]]
print(out2[0].numpy())
# [[[5. 2. 4. 2.]
# [0. 0. 1. 7.]
# [1. 7. 0. 4.]]
# [[5. 8. 9. 5.]
# [4. 7. 7. 9.]
# [6. 9. 2. 6.]]]
print(out3[0].numpy())
# [[[0. 0. 1. 4.]
# [5. 8. 2. 5.]
# [6. 9. 9. 7.]]
# [[1. 2. 0. 2.]
# [4. 7. 4. 6.]
# [5. 7. 7. 9.]]]
.. _cn_api_paddle_tensor_split
split
-------------------------------
.. py:function:: paddle.tensor.split(input, num_or_sections, dim=-1, name=None)
该OP将输入Tensor分割成多个子Tensor。
**参数**:
- **input** (Variable) - 输入变量,数据类型为float32,float64,int32,int64的多维Tensor或者LoDTensor。
- **num_or_sections** (int|list|tuple) - 如果 num_or_sections 是一个整数,则表示Tensor平均划分为相同大小子Tensor的数量。如果 num_or_sections 是一个list或tuple,那么它的长度代表子Tensor的数量,它的元素可以是整数或者形状为[1]的Tensor,依次代表子Tensor需要分割成的维度的大小。list或tuple的长度不能超过输入Tensor待分割的维度的大小。在list或tuple中,至多有一个元素值为-1,表示该值是由input的维度和其他num_or_sections中元素推断出来的。例如对一个维度为[4,6,6]Tensor的第三维进行分割时,指定num_or_sections=[2,-1,1],输出的三个Tensor维度分别为:[4,6,2],[4,6,3],[4,6,1]。
- **dim** (int|Variable,可选) - 整数或者形状为[1]的Tensor,数据类型为int32或int64。表示需要分割的维度。如果dim < 0,则划分的维度为rank(input) + dim。默认值为-1。
- **name** (str,可选) - 一般无需设置,默认值为None。
**返回**:分割后的Tensor列表。
**返回类型**:列表(Variable(Tensor|LoDTensor)),数据类型为int32,int64,float32,float64。
**代码示例**:
.. code-block:: python
import paddle
import paddle.fluid as fluid
import numpy as np
with fluid.dygraph.guard():
input_1 = np.random.random([4, 6, 6]).astype("int32")
# input is a variable which shape is [4, 6, 6]
input = fluid.dygraph.to_variable(input_1)
x0, x1, x2 = paddle.split(input, num_or_sections= 3, dim=1)
# x0.shape [4, 2, 6]
# x1.shape [4, 2, 6]
# x2.shape [4, 2, 6]
.. _cn_api_tensor_sqrt:
sqrt
-------------------------------
.. py:function:: paddle.sqrt(x, name=None, out=None)
计算输入的算数平方根。
.. math::
out=\sqrt x=x^{1/2}
.. note::
请确保输入中的数值是非负数。
参数:
- **x** (Variable) - 支持任意维度的Tensor。数据类型为float32,float64或float16。
- **name** (str,可选) – 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。
- **out** (Variable, 可选) – 指定存储运算结果的Tensor。如果设置为None或者不设置,将创建新的Tensor存储运算结果,默认值为None。
返回:返回类型为Variable(Tensor|LoDTensor), 数据类型同输入一致。
**代码示例**:
.. code-block:: python
import numpy as np
import paddle
import paddle.fluid as fluid
inputs = fluid.layers.data(name="x", shape = [3], dtype='float32')
output = paddle.sqrt(inputs)
exe = fluid.Executor(fluid.CPUPlace())
exe.run(fluid.default_startup_program())
img = np.array([0, 9, 36]).astype(np.float32)
res = exe.run(fluid.default_main_program(), feed={'x':img}, fetch_list=[output])
print(res)
# [array([0., 3., 6.], dtype=float32)]
.. _cn_api_paddle_tensor_squeeze
squeeze
-------------------------------
.. py:function:: paddle.tensor.squeeze(input, zxes, name=None)
该OP会根据axes压缩输入Tensor的维度。如果指定了axes,则会删除axes中指定的维度,axes指定的维度要等于1。如果没有指定axes,那么所有等于1的维度都会被删除。
**参数**:
- **input** (Variable) - 输入任意维度的Tensor。 支持的数据类型:float32,float64,int8,int32,int64。
- **axes** (list) - 输入一个或一列整数,代表要压缩的轴。axes的范围: [−rank(input),rank(input))] 。 axes为负数时, axes=axes+rank(input) 。
- **name** (str,可选) - 一般无需设置,默认值为None。
**返回**:返回对维度进行压缩后的Tensor。数据类型与输入Tensor一致。
**返回类型**:Variable
**代码示例**:
.. code-block:: python
import paddle
import paddle.fluid as fluid
import numpy as np
with fluid.dygraph.guard():
input_1 = np.random.random([5, 1, 10]).astype("int32")
# input is a variable which shape is [5, 1, 10]
input = fluid.dygraph.to_variable(input_1)
output = paddle.fluid.layers.squeeze(input, axes=[1])
# output.shape [5, 10]
.. _cn_api_paddle_tensor_arange
stack
-------------------------------
.. py:function:: paddle.tensor.stack(x, axis=0)
该OP沿 axis 轴对输入 x 进行堆叠操作。
**参数**:
- **x** (Variable|list(Variable)) – 输入 x 可以是单个Tensor,或是多个Tensor组成的列表。如果 x 是一个列表,那么这些Tensor的维度必须相同。 假设输入是N维Tensor [d0,d1,...,dn−1],则输出变量的维度为N+1维 [d0,d1,...daxis−1,len(x),daxis...,dn−1] 。支持的数据类型: float32,float64,int32,int64。
- **axis** (int, 可选) – 指定对输入Tensor进行堆叠运算的轴,有效 axis 的范围是: [−(R+1),R+1)],R是输入中第一个Tensor的rank。如果 axis < 0,则 axis=axis+rank(x[0])+1 。axis默认值为0。
**返回**:堆叠运算后的Tensor,数据类型与输入Tensor相同。输出维度等于 rank(x[0])+1 维。
**返回类型**:Variable
**代码示例**:
.. code-block:: python
import paddle
import paddle.fluid as fluid
import numpy as np
data1 = np.array([[1.0, 2.0,3.0]])
data2 = np.array([[3.0, 4.0, 5.0]])
data3 = np.array([[5.0, 6.0,7.0]])
with fluid.dygraph.guard():
x1 = fluid.dygraph.to_variable(data1)
x2 = fluid.dygraph.to_variable(data2)
x3 = fluid.dygraph.to_variable(data3)
result = paddle.stack([x1, x2, x3], axis=2)
# result shape: [3, 1, 2]
# result value: [[[1.0, 2.0]],
# [[3.0, 4.0]],
# [[5.0, 6.0]]]
std
-------------------------------
**版本升级,文档正在开发中**
.. _cn_api_tensor_sum:
sum
-------------------------------
.. py:function:: paddle.sum(input, dim=None, dtype=None, keep_dim=False, name=None)
该OP是对指定维度上的Tensor元素进行求和运算,并输出相应的计算结果。
参数:
- **input** (Variable)- 输入变量为多维Tensor或LoDTensor,支持数据类型为float32,float64,int32,int64。
- **dim** (list | int ,可选)- 求和运算的维度。如果为None,则计算所有元素的和并返回包含单个元素的Tensor变量,否则必须在 :math:`[−rank(input),rank(input)]` 范围内。如果 :math:`dim [i] <0` ,则维度将变为 :math:`rank+dim[i]` ,默认值为None。
- **dtype** (str , 可选)- 输出变量的数据类型。若参数为空,则输出变量的数据类型和输入变量相同,默认值为None。
- **keep_dim** (bool)- 是否在输出Tensor中保留减小的维度。如 keep_dim 为true,否则结果张量的维度将比输入张量小,默认值为False。
- **name** (str , 可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。
返回: 在指定dim上进行求和运算的Tensor,数据类型和输入数据类型一致。
返回类型: 变量(Variable)
**代码示例**
.. code-block:: python
import paddle
import paddle.fluid as fluid
# x是一个Tensor,元素如下:
# [[0.2, 0.3, 0.5, 0.9]
# [0.1, 0.2, 0.6, 0.7]]
# 接下来的示例中,我们在每处函数调用后面都标注出了它的结果张量。
x = fluid.data(name='x', shape=[2, 4], dtype='float32')
out1 = paddle.sum(x) # [3.5]
out2 = paddle.sum(x, dim=0) # [0.3, 0.5, 1.1, 1.6]
out3 = paddle.sum(x, dim=-1) # [1.9, 1.6]
out4 = paddle.sum(x, dim=1, keep_dim=True) # [[1.9], [1.6]]
# y 是一个shape为[2, 2, 2]的Tensor元素如下:
# [[[1, 2], [3, 4]],
# [[5, 6], [7, 8]]]
# 接下来的示例中,我们在每处函数调用后面都标注出了它的结果张量。
y = fluid.data(name='y', shape=[2, 2, 2], dtype='float32')
out5 = paddle.sum(y, dim=[1, 2]) # [10, 26]
out6 = paddle.sum(y, dim=[0, 1]) # [16, 20]
......@@ -3,7 +3,7 @@
t
-------------------------------
.. py:function:: paddle.fluid.layers.t(input, name=None)
.. py:function:: paddle.tensor.t(input, name=None)
该OP对小于等于2维的Tensor进行数据转置。0维和1维Tensor返回本身,2维Tensor等价于perm设置为0,1的 :ref:`cn_api_fluid_layers_transpose` 函数。
......@@ -21,16 +21,16 @@ t
# 例1 (0-D tensor)
x = tensor([0.79])
fluid.layers.t(x) = tensor([0.79])
paddle.t(x) = tensor([0.79])
# 例2 (1-D tensor)
x = tensor([0.79, 0.84, 0.32])
fluid.layers.t(x) = tensor([0.79, 0.84, 0.32])
paddle.t(x) = tensor([0.79, 0.84, 0.32])
# 例3 (2-D tensor)
x = tensor([0.79, 0.84, 0.32],
[0.64, 0.14, 0.57])
fluid.layers.t(x) = tensor([0.79, 0.64],
paddle.t(x) = tensor([0.79, 0.64],
[0.84, 0.14],
[0.32, 0.57])
......@@ -42,7 +42,7 @@ t
import paddle
import paddle.fluid as fluid
x = fluid.data(name='x', shape=[2, 3], dtype='float32')
x_transposed = fluid.layers.t(x) # paddle.t 等价于 paddle.tensor.t
x_transposed = paddle.t(x) # paddle.t 等价于 paddle.tensor.t
print(x_transposed.shape)
#(3L, 2L)
.. _cn_api_tensor_tanh:
tanh
-------------------------------
.. py:function:: paddle.tanh(x, name=None, out=None)
tanh 激活函数
.. math::
out = \frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}
参数:
- **x** (Variable) - 支持任意维度的Tensor。数据类型为float32,float64或float16。
- **name** (str,可选) – 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。
- **out** (Variable, 可选) – 指定存储运算结果的Tensor。如果设置为None或者不设置,将创建新的Tensor存储运算结果,默认值为None。
返回:返回类型为Variable(Tensor|LoDTensor), 数据类型同输入一致。
**代码示例**:
.. code-block:: python
import numpy as np
import paddle
import paddle.fluid as fluid
inputs = fluid.layers.data(name="x", shape = [3], dtype='float32')
output = paddle.tanh(inputs)
exe = fluid.Executor(fluid.CPUPlace())
exe.run(fluid.default_startup_program())
img = np.array([0, 0.5, 0.3]).astype(np.float32)
res = exe.run(fluid.default_main_program(), feed={'x':img}, fetch_list=[output])
print(res)
# [array([0., 0.46211717, 0.2913126], dtype=float32)]
tensordot
-------------------------------
**版本升级,文档正在开发中**
transpose
-------------------------------
**版本升级,文档正在开发中**
unbind
-------------------------------
**版本升级,文档正在开发中**
.. _cn_api_paddle_tensor_unsqueeze
unsqueeze
-------------------------------
.. py:function:: paddle.tensor.unsqueeze(input, axes, name=None)
该OP向输入(input)的shape中一个或多个位置(axes)插入维度。
**参数**:
- **input** (Variable)- 多维 Tensor,数据类型为 float32, float64, int8, int32,或 int64。
- **axes** (int|list|tuple|Variable) - 表示要插入维度的位置。数据类型是 int32 。如果 axes 的类型是 list 或 tuple,它的元素可以是整数或者形状为[1]的 Tensor 。如果 axes 的类型是 Variable,则是1-D Tensor。
- **name** (str,可选)- 一般无需设置。默认值: None。
**返回**:扩展维度后的多维Tensor
**返回类型**:Variable
**代码示例**:
.. code-block:: python
import paddle
import paddle.fluid as fluid
import numpy as np
with fluid.dygraph.guard():
input_1 = np.random.random([5, 10]).astype("int32")
# input is a variable which shape is [5, 1, 10]
input = fluid.dygraph.to_variable(input_1)
output = paddle.unsqueeze(input, axes=[1])
# output.shape [5, 1, 10]
var
-------------------------------
**版本升级,文档正在开发中**
.. _cn_api_tensor_zeros:
zeros
-------------------------------
.. py:function:: paddle.zeros(shape, dtype, out=None, device=None)
该OP创建形状为 ``shape`` 、数据类型为 ``dtype`` 且值全为0的Tensor。
参数:
- **shape** (tuple|list) - 输出Tensor的形状。
- **dtype** (np.dtype|core.VarDesc.VarType|str) - 输出Tensor的数据类型,数据类型必须为float16、float32、float64、int32或int64。
- **out** (Variable, 可选) – 指定存储运算结果的Tensor。如果设置为None或者不设置,将创建新的Tensor存储运算结果,默认值为None。
- **device** (str,可选) – 选择在哪个设备运行该操作,可选值包括None,'cpu'和'gpu'。如果 ``device`` 为None,则将选择运行Paddle程序的设备,默认为None。
返回:值全为0的Tensor,数据类型和 ``dtype`` 定义的类型一致。
返回类型:Variable
**代码示例**:
.. code-block:: python
import paddle
data = paddle.zeros(shape=[3, 2], dtype='float32') # [[0., 0.], [0., 0.], [0., 0.]]
data = paddle.zeros(shape=[2, 2], dtype='float32', device='cpu') # [[0., 0.], [0., 0.]]
.. _cn_api_tensor_zeros_like:
zeros_like
-------------------------------
.. py:function:: paddle.zeros_like(input, dtype=None, device=None, name=None)
该OP创建一个和input具有相同的形状和数据类型的全零Tensor。
参数:
- **input** (Variable) – 指定输入为一个多维的Tensor,数据类型可以是bool,float32,float64,int32,int64。
- **dtype** (np.dtype|core.VarDesc.VarType|str, 可选)- 输出变量的数据类型。若参数为空,则输出变量的数据类型和输入变量相同,默认值为None。
- **device** (str,可选) – 选择在哪个设备运行该操作,可选值包括None,'cpu'和'gpu'。如果 ``device`` 为None,则将选择运行Paddle程序的设备,默认为None。
- **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。
返回:返回一个存储结果的Tensor。
返回类型:Variable
**代码示例**:
.. code-block:: python
import paddle
import paddle.fluid as fluid
x = fluid.data(name='x', dtype='float32', shape=[3])
data1 = paddle.ones_like(input=x, device="gpu") # data1=[1.0, 1.0. 1.0]
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册