Replace all nonzero values by zero and all zero values by a specific value

Its a simple question but I need help. I have a tensor which contains some zero and nonzero values. I want to replace all nonzero values by zero and zero values by a specific value. How can I do that?

output = (input == 0).float().mul_(value)

3 Likes