pytorch张量 - 随机替换满足条件的值
我有一个pytorch张量尺寸的蒙版
torch.Size([8, 24, 24])
具有独特的值,
> torch.unique(mask, return_counts=True)
(tensor([0, 1, 2]), tensor([2093, 1054, 1461]))
我希望随机将2s的数量随机替换为0s,以使张量的唯一值和计数变成,
> torch.unique(mask, return_counts=True)
(tensor([0, 1, 2]), tensor([2500, 1054, 1054]))
我尝试使用 TORCH。
没有成功。如何实现?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能的解决方案之一是通过
查看
和numpy.random.Choice
:One of the possible solutions is through flattening via
view
andnumpy.random.choice
: