New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
【PaddlePaddle Hackathon 3】15 新增 API count_nonzero #5085
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,6 +104,7 @@ Methods | |
copy_ | ||
cos | ||
cosh | ||
count_nonzero | ||
cpu | ||
cross | ||
cuda | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
.. _cn_api_tensor_cn_count_nonzero: | ||
|
||
count_nonzero | ||
------------------------------- | ||
|
||
.. py:function:: paddle.count_nonzero(x, axis=None, keepdim=False, name=None) | ||
|
||
沿给定的轴 ``axis`` 统计输入Tensor ``x`` 中非零元素的个数。 | ||
|
||
参数 | ||
:::::::::: | ||
- x (Tensor) - 输入的Tensor,数据类型为:bool、float16、float32、float64、int32、int64。 | ||
- axis (None|int|list|tuple,可选) - 指定对 ``x`` 进行计算的轴。``axis`` 可以是int或者int元素的列表。``axis`` 值应该在范围[-D, D)内,D是 ``x`` 的维度。如果 ``axis`` 或者其中的元素值小于0,则等价于 :math:`axis + D`。如果 ``axis`` 是None,则对 ``x`` 的全部元素计算中位数。默认值为None。 | ||
- keepdim (bool,可选) - 是否在输出Tensor中保留减小的维度。如果 ``keepdim`` 为True,则输出Tensor和 ``x`` 具有相同的维度(减少的维度除外,减少的维度的大小为1)。否则,输出Tensor的形状会在 ``axis`` 上进行squeeze操作。默认值为True。 | ||
- **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为 None。 | ||
|
||
|
||
返回 | ||
:::::::::: | ||
``Tensor``,沿着 ``axis`` 统计输入Tensor中非零元素的个数,数据类型int64。 | ||
|
||
代码示例 | ||
:::::::::: | ||
COPY-FROM: paddle.count_nonzero:count_nonzero-example |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.