nonzero(*, bool as_tuple) (Triggered internally at ..\torch\csrc\utils\python_arg_parser.cpp:882.)
时间: 2023-07-21 12:08:08 浏览: 87
It seems that you are encountering an error message related to the `nonzero` function in PyTorch.
The `nonzero` function returns the indices of nonzero elements in a tensor. It optionally takes a `bool as_tuple` argument, which specifies whether to return a tuple of vectors for each dimension of the input tensor (if `as_tuple=True`) or a two-dimensional tensor where each row contains the indices of a nonzero element (if `as_tuple=False`, which is the default).
The error message you are seeing suggests that there is an issue with the `bool as_tuple` argument. One possible cause could be that you are passing an argument that is not a boolean value (i.e., `True` or `False`).
To resolve the issue, you can try explicitly specifying the `as_tuple` argument with a boolean value when calling the `nonzero` function. For example:
```
import torch
# create a tensor
x = torch.tensor([0, 1, 0, 2, 3])
# get the indices of nonzero elements as a tuple of vectors
indices_tuple = torch.nonzero(x, as_tuple=True)
print(indices_tuple)
# get the indices of nonzero elements as a two-dimensional tensor
indices_tensor = torch.nonzero(x)
print(indices_tensor)
```
If the issue persists, please provide more context or code snippets so that I can better assist you.
阅读全文