Skip to content

Value of type 'at::Tensor' is not contextually convertible to 'bool' error #37480

@neozhang-icommute

Description

@neozhang-icommute

❓ Questions and Help

My code sample:

auto a = torch::rand({2,3});
a = a>0.5;

for (int i = 0; i<2; i++)
    for (int j = 0; i<3; j++)
    {
        if (a.index({i, j}))
        {
            std::cout<<"true"<<std::endl;
        }
    }

There exists a error "Value of type 'at::Tensor' is not contextually convertible to 'bool' error" in if (a.index({i, j})).

How to modify it?

Thanks

Please note that this issue tracker is not a help form and this issue will be closed.

We have a set of listed resources available on the website. Our primary means of support is our discussion forum:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions