@@ -3751,25 +3751,37 @@ def merge_dicts(*dicts):
37513751 r"""
37523752nonzero(input, *, out=None, as_tuple=False) -> LongTensor or tuple of LongTensors
37533753
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)**:
37553767
37563768Returns a tensor containing the indices of all non-zero elements of
37573769:attr:`input`. Each row in the result contains the indices of a non-zero
37583770element in :attr:`input`. The result is sorted lexicographically, with
37593771the last index changing the fastest (C-style).
37603772
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
37623774:attr:`out` is of size :math:`(z \times n)`, where :math:`z` is the total number of
37633775non-zero elements in the :attr:`input` tensor.
37643776
3765- **When** :attr:`as_tuple` **is true:**
3777+ **When** :attr:`as_tuple` **is ``True``**:
37663778
37673779Returns a tuple of 1-D tensors, one for each dimension in :attr:`input`,
37683780each containing the indices (in that dimension) of all non-zero elements of
37693781:attr:`input` .
37703782
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
37733785non-zero elements in the :attr:`input` tensor.
37743786
37753787As a special case, when :attr:`input` has zero dimensions and a nonzero scalar
@@ -3780,8 +3792,8 @@ def merge_dicts(*dicts):
37803792 out (LongTensor, optional): the output tensor containing indices
37813793
37823794Returns:
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
37853797 each dimension, containing the indices of each nonzero element along that
37863798 dimension.
37873799
0 commit comments