Hi, I have tensor slicing problem here:
In python:
I can use output[ output < 0.5 ] = 0
to set somevalues to 0
In C++:
I don’t know how to do it.
I think the .index()
method is used to mimick the []
behavior.
You might want to check the doc in details though as I’m not sure what this function can do exactly
Thanks for your hint, I’ve checked the docs, there is no condition indexing method found.
Interesting.
Then you’ll have to use masked_fill directly then I guess https://pytorch.org/cppdocs/api/function_namespaceat_1a5118bdabdb9cc642a7a12ceaacfd0531.html?highlight=masked_fill
any example to create a mask?
This is actually creating a boolean Tensor with the mask you want
Thank you, I’ve found the solution, and tested it.
output.index_put_({output < 0.5}, 0)
1 Like