Skip to content
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
2 changes: 2 additions & 0 deletions docs/api/paddle/Overview_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ tensor 元素操作相关(如:转置,reshape 等)
" :ref:`paddle.expand_as <cn_api_paddle_expand_as>` ", "根据 y 的形状扩展 x ,扩展后, x 的形状和 y 的形状相同"
" :ref:`paddle.flatten <cn_api_paddle_flatten>` ", "根据给定的 start_axis 和 stop_axis 将连续的维度展平"
" :ref:`paddle.flip <cn_api_paddle_flip>` ", "沿指定轴反转 n 维 tensor"
" :ref:`paddle.ravel <cn_api_paddle_ravel>` ", "返回一个连续的展平的 tensor"
" :ref:`paddle.rot90 <cn_api_paddle_rot90>` ", "沿 axes 指定的平面将 n 维 tensor 旋转 90 度 k 次"
" :ref:`paddle.gather <cn_api_paddle_gather>` ", "根据索引 index 获取输入 x 的指定 axis 维度的条目,并将它们拼接在一起"
" :ref:`paddle.gather_nd <cn_api_paddle_gather_nd>` ", "paddle.gather 的高维推广"
Expand Down Expand Up @@ -562,6 +563,7 @@ tensor 元素操作相关(如:转置,reshape 等)
" :ref:`paddle.hstack <cn_api_paddle_hstack>` ", "沿水平轴堆叠输入 x 中的所有张量。"
" :ref:`paddle.vstack <cn_api_paddle_vstack>` ", "沿垂直轴堆叠输入 x 中的所有张量。"
" :ref:`paddle.dstack <cn_api_paddle_dstack>` ", "沿深度轴堆叠输入 x 中的所有张量。"
" :ref:`paddle.narrow <cn_api_paddle_narrow>` ", "沿指定维度 dim 对输入 x 进行切片。"

.. _tensor_manipulation_inplace:

Expand Down
16 changes: 14 additions & 2 deletions docs/api/paddle/Tensor_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -822,15 +822,27 @@ half()

返回: 转换后的 Tensor

type_as(other)
:::::::::

将当前 Tensor 的数据类型转换至与目标 Tensor 相同。

参数:
- **other** (Tensor) -用作类型参考的张量,返回的新 Tensor 将与其 dtype 保持一致。

返回:类型转换后的新的 Tensor

返回类型:Tensor

**代码示例**
.. code-block:: python

import paddle
x = paddle.to_tensor(1.0)
x = paddle.to_tensor([1, 2, 3], dtype='int32')
y = paddle.to_tensor([4.0, 5.0, 6.0], dtype='float32')
x_float = x.type_as(y)
print("original tensor's dtype is: {}".format(x.dtype))
print("new tensor's dtype is: {}".format(x.half().dtype))
print("new tensor's dtype is: {}".format(x_float.dtype))

int()
:::::::::
Expand Down
25 changes: 25 additions & 0 deletions docs/api/paddle/narrow_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.. _cn_api_paddle_narrow:

narrow
-------------------------------

.. py:function:: paddle.narrow(input, dim, start, length)

返回输入张量 input 在指定维度 dim 上的窄切片。
该操作保留所有维度,仅沿 dim 选取索引区间 [start, start + length) 内的元素,则返回结果与输入共享内存(视图)。

参数
:::::::::
- **input** (Tensor) - 输入张量,支持任意数据类型与形状。
- **dim** (int) - 要窄化的维度,支持负索引。
- **start** (int|Tensor) - 起始索引,可为 Python 整数或 0-D 的 int32/int64 张量,负值表示从维度末尾倒数。
- **length** (int) - 从 start 开始选取的元素个数,必须 ≥ 0。

返回
:::::::::
``Tensor``,与 input 数据类型相同,形状仅在 dim 维变为 length,其余维不变。

代码示例
:::::::::

COPY-FROM: paddle.narrow
9 changes: 7 additions & 2 deletions docs/api/paddle/nn/Sequential_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@ Sequential

.. py:class:: paddle.nn.Sequential(*layers)

顺序容器。子 Layer 将按构造函数参数的顺序依次添加到此容器中。
参数支持以下三种形式:

1. 逐个 Layer 实例:Sequential(layer1, layer2, ...)
2. 带名字的 (name, layer) 对:Sequential(('l1', layer1), ('l2', layer2))
3. OrderedDict:Sequential(OrderedDict([('l1', layer1), ('l2', layer2)]))

可通过 整数下标 或 字符串名字 访问、修改、新增子层;支持 append、insert、extend 等列表式操作。

顺序容器。子 Layer 将按构造函数参数的顺序添加到此容器中。传递给构造函数的参数可以是 Layers 或可迭代的 name Layer 元组。

参数
::::::::::::

- **layers** (tuple) - Layers 或可迭代的 name Layer 对
- **layers** (Layer|tuple(str, Layer)|list|OrderedDict) - 任意数量的 Layer 对象,或 (name, layer) 可迭代结构,或一个 OrderedDict

返回
::::::::::::
Expand Down
23 changes: 23 additions & 0 deletions docs/api/paddle/ravel_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.. _cn_api_paddle_ravel:

ravel
-------------------------------

.. py:function:: paddle.ravel(input)
返回输入张量 input 的一个展平(一维)视图。

该函数会将输入 Tensor 按行优先(C-style)顺序展平成一个 1 维张量。如果输入 Tensor 已经是连续内存,则返回的结果与原 Tensor 共享数据(即为视图);如果不连续,则会返回一份连续的拷贝。
在 动态图 模式下,返回的 Tensor 默认与输入 Tensor 共享数据。如果需要得到一份新的数据拷贝,可以使用 Tensor.clone 方法,例如:ravel_clone_x = x.ravel().clone()。

参数
:::::::::
- **input** (Tensor) - 输入的张量,数据类型为 float16、float32、float64、int8、int32、int64、uint8 等,维度任意。

返回
:::::::::
输出 一维 Tensor,包含输入张量的所有元素,数据类型与输入相同。

代码示例
:::::::::

COPY-FROM: paddle.ravel