@@ -3751,25 +3751,37 @@ def merge_dicts(*dicts):
3751
3751
r"""
3752
3752
nonzero(input, *, out=None, as_tuple=False) -> LongTensor or tuple of LongTensors
3753
3753
3754
- **When** :attr:`as_tuple` **is false or unspecified:**
3754
+ .. note::
3755
+ :func:`torch.nonzero(..., as_tuple=False) <torch.nonzero>` (default) returns a
3756
+ 2-D tensor where each row is the index for a nonzero value.
3757
+
3758
+ :func:`torch.nonzero(..., as_tuple=True) <torch.nonzero>` returns a tuple of 1-D
3759
+ index tensors, allowing for advanced indexing, so ``x[x.nonzero(as_tuple=True)]``
3760
+ gives all nonzero values of tensor ``x``. Of the returned tuple, each index tensor
3761
+ contains nonzero indices for a certain dimension.
3762
+
3763
+ See below for more details on the two behaviors.
3764
+
3765
+
3766
+ **When** :attr:`as_tuple` **is ``False`` (default)**:
3755
3767
3756
3768
Returns a tensor containing the indices of all non-zero elements of
3757
3769
:attr:`input`. Each row in the result contains the indices of a non-zero
3758
3770
element in :attr:`input`. The result is sorted lexicographically, with
3759
3771
the last index changing the fastest (C-style).
3760
3772
3761
- If :attr:`input` has `n` dimensions, then the resulting indices tensor
3773
+ If :attr:`input` has :math: `n` dimensions, then the resulting indices tensor
3762
3774
:attr:`out` is of size :math:`(z \times n)`, where :math:`z` is the total number of
3763
3775
non-zero elements in the :attr:`input` tensor.
3764
3776
3765
- **When** :attr:`as_tuple` **is true:**
3777
+ **When** :attr:`as_tuple` **is ``True``**:
3766
3778
3767
3779
Returns a tuple of 1-D tensors, one for each dimension in :attr:`input`,
3768
3780
each containing the indices (in that dimension) of all non-zero elements of
3769
3781
:attr:`input` .
3770
3782
3771
- If :attr:`input` has `n` dimensions, then the resulting tuple contains `n` tensors
3772
- of size `z`, where `z` is the total number of
3783
+ If :attr:`input` has :math: `n` dimensions, then the resulting tuple contains :math: `n`
3784
+ tensors of size :math: `z`, where :math: `z` is the total number of
3773
3785
non-zero elements in the :attr:`input` tensor.
3774
3786
3775
3787
As a special case, when :attr:`input` has zero dimensions and a nonzero scalar
@@ -3780,8 +3792,8 @@ def merge_dicts(*dicts):
3780
3792
out (LongTensor, optional): the output tensor containing indices
3781
3793
3782
3794
Returns:
3783
- LongTensor or tuple of LongTensor: If :attr:`as_tuple` is false , the output
3784
- tensor containing indices. If :attr:`as_tuple` is true , one 1-D tensor for
3795
+ LongTensor or tuple of LongTensor: If :attr:`as_tuple` is ``False`` , the output
3796
+ tensor containing indices. If :attr:`as_tuple` is ``True`` , one 1-D tensor for
3785
3797
each dimension, containing the indices of each nonzero element along that
3786
3798
dimension.
3787
3799
0 commit comments