Skip to content

Commit

Permalink
add bincount api cn doc (#3959) (#4011)
Browse files Browse the repository at this point in the history
* add bincount api cn doc

* fix cn doc

* add name
  • Loading branch information
smallv0221 authored Oct 27, 2021
1 parent 291f4dd commit 05ffe99
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/api/paddle/Overview_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ tensor线性代数相关
:header: "API名称", "API功能"
:widths: 10, 30

" :ref:`paddle.bincount <cn_api_tensor_bincount>` ", "统计输入张量中元素的出现次数"
" :ref:`paddle.bmm <cn_api_paddle_tensor_bmm>` ", "对输入x及输入y进行矩阵相乘"
" :ref:`paddle.cholesky <cn_api_tensor_cholesky>` ", "计算一个对称正定矩阵或一批对称正定矩阵的Cholesky分解"
" :ref:`paddle.cross <cn_api_tensor_linalg_cross>` ", "计算张量 x 和 y 在 axis 维度上的向量积(叉积)"
Expand Down
9 changes: 9 additions & 0 deletions docs/api/paddle/Tensor_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,15 @@ backward(grad_tensor=None, retain_graph=False)
# 3: [4000.]
# 4: [5000.]
bincount(weights=None, minlength=0)
:::::::::

返回:计算后的Tensor

返回类型:Tensor

请参考 :ref:`cn_api_tensor_bincount`

bitwise_and(y, out=None, name=None)
:::::::::

Expand Down
37 changes: 37 additions & 0 deletions docs/api/paddle/bincount_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.. _cn_api_tensor_bincount:

bincount
-------------------------------

.. py:function:: paddle.bincount(x, weights=None, minlength=0, name=None):
统计输入张量中每个元素出现的次数,如果传入weights张量则每次计数加一时会乘以weights张量对应的值

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

- **x** (Tensor) - 输入Tensor。必须是一维Tensor,其中元素必须大于等于0,数据类型为int32, int64。
- **weights** (Tensor, 可选) - weights Tensor,代表输入Tensor中每个元素的权重。长度必须与输入Tensor相同。数据类型为int32, int64, float32或float64。默认为None
- **minlength** (int, 可选) - 输出Tensor的最小长度,如果大于输入Tensor的长度,则多出的位置补0。该值必须大于等于0。默认为0。
- **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。

返回:
::::::::::::
Tensor,维度为1。

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

.. code-block:: python
import paddle
x = paddle.to_tensor([1, 2, 1, 4, 5])
result1 = paddle.bincount(x)
print(result1) # [0, 2, 1, 0, 1, 1]
w = paddle.to_tensor([2.1, 0.4, 0.1, 0.5, 0.5])
result2 = paddle.bincount(x, weights=w)
print(result2) # [0., 2.19999981, 0.40000001, 0., 0.50000000, 0.50000000]

0 comments on commit 05ffe99

Please sign in to comment.