diff --git a/doc/fluid/api/paddle.rst b/doc/fluid/api/paddle.rst index 8f9717c1def3bd8bee865386258266eeeaa8bb43..9670615d732cf8ae64a320f15dbde1c2d2eeefce 100644 --- a/doc/fluid/api/paddle.rst +++ b/doc/fluid/api/paddle.rst @@ -97,6 +97,7 @@ paddle paddle/logical_xor.rst paddle/logsumexp.rst paddle/manual_seed.rst + paddle/masked_select.rst paddle/matmul.rst paddle/max.rst paddle/maximum.rst diff --git a/doc/fluid/api/tensor.rst b/doc/fluid/api/tensor.rst index 82ac61c6edd612e6d304d5fcca73001076d07faa..b79132329944bd42e8573bf65b2fbc58d2a155f9 100644 --- a/doc/fluid/api/tensor.rst +++ b/doc/fluid/api/tensor.rst @@ -67,6 +67,7 @@ paddle.tensor tensor/logical_or.rst tensor/logical_xor.rst tensor/math.rst + tensor/masked_select.rst tensor/max.rst tensor/maximum.rst tensor/mean.rst diff --git a/doc/fluid/api/tensor/masked_select.rst b/doc/fluid/api/tensor/masked_select.rst new file mode 100644 index 0000000000000000000000000000000000000000..b3e0d11be9c38ba8e7459903e0198a8d1e39676d --- /dev/null +++ b/doc/fluid/api/tensor/masked_select.rst @@ -0,0 +1,11 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_tensor_search_masked_select: + +masked_select +--------------- + +.. autofunction:: paddle.tensor.search.masked_select + :noindex: + diff --git a/doc/fluid/api_cn/paddle_cn.rst b/doc/fluid/api_cn/paddle_cn.rst index 47782281636bd6f85cf2876e53918a701d35cd97..2e6632b2befad50ca3cf723e46ce204298e02b39 100644 --- a/doc/fluid/api_cn/paddle_cn.rst +++ b/doc/fluid/api_cn/paddle_cn.rst @@ -96,6 +96,7 @@ paddle paddle_cn/logsumexp_cn.rst paddle_cn/log_cn.rst paddle_cn/manual_seed_cn.rst + paddle_cn/masked_select_cn.rst paddle_cn/matmul_cn.rst paddle_cn/max_cn.rst paddle_cn/maximum_cn.rst diff --git a/doc/fluid/api_cn/tensor_cn.rst b/doc/fluid/api_cn/tensor_cn.rst index 99212fedaa2f4b1aa45c0d132ff163c5698b2149..2faa62d9b97f6a989b6ac61df05b1a48ad72f6d5 100644 --- a/doc/fluid/api_cn/tensor_cn.rst +++ b/doc/fluid/api_cn/tensor_cn.rst @@ -92,6 +92,7 @@ paddle.tensor tensor_cn/logical_or_cn.rst tensor_cn/logical_xor_cn.rst tensor_cn/logsumexp_cn.rst + tensor_cn/masked_select_cn.rst tensor_cn/math_cn.rst tensor_cn/matmul_cn.rst tensor_cn/max_cn.rst diff --git a/doc/fluid/api_cn/tensor_cn/masked_select_cn.rst b/doc/fluid/api_cn/tensor_cn/masked_select_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..cecffda2c283dde127660a0a1b7083f64dbe102d --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/masked_select_cn.rst @@ -0,0 +1,43 @@ +.. _cn_api_tensor_masked_select: + +masked_select +------------------------------- + +.. py:function:: paddle.masked_select(x, mask, name=None) + + + +该OP返回一个1-D 的Tensor, Tensor的值是根据 ``mask`` 对输入 ``x`` 进行选择的, ``mask`` 的数据类型是bool 。 + +参数: + - **x** (Tensor) - 输入Tensor, 数据类型为float32, float64,int32 或者int64。 + - **mask** (Tensor) - 用于索引的二进制掩码的Tensor,数据类型维bool。 + - **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 + +返回:返回一个根据 ``mask`` 选择的的Tensor + + +抛出异常: + - ``TypeError``: - 如果 ``x`` 不是 Tensor 或者 ``x`` 是Tensor的时候的数据类型不是 float32, float64, int32, int64其中之一。 + - ``TypeError``: - 如果 ``mask`` 不是 Tensor 或者 ``mask`` 是Tensor的时候的数据类型不是 bool。 + +**代码示例**: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.disable_static() + data = np.array([[1.0, 2.0, 3.0, 4.0], + [5.0, 6.0, 7.0, 8.0], + [9.0, 10.0, 11.0, 12.0]]).astype('float32') + + mask_data = np.array([[True, False, False, False], + [True, True, False, False], + [True, False, False, False]]).astype('bool') + x = paddle.to_tensor(data) + mask = paddle.to_tensor(mask_data) + out = paddle.masked_select(x, mask) + #[1.0 5.0 6.0 9.0] +