admin管理员组文章数量:1332873
In this code:
a_numpy = np.array([1,2,3])
a_torch = torch.tensor([1,2,3])
index_torch = torch.tensor([[0]])
index_np = np.array([[0]])
print(f"{a_numpy[index_torch]=}")
print(f"{a_numpy[index_np]=}")
print(f"{a_torch[index_torch]=}")
print(f"{a_torch[index_np]=}")
it prints:
a_numpy[index_torch]=np.int64(1)
a_numpy[index_np]=array([[1]])
a_torch[index_torch]=tensor([[1]])
a_torch[index_np]=tensor([[1]])
notice the odd one out a_numpy[index_torch]=np.int64(1)
. Why does this happen? Is this a bug?
numpy version: 2.0.2 torch version: 2.5.1
本文标签:
版权声明:本文标题:python - When using numpy advanced indexing with a torch tensor, it sometimes will squeeze dimensions - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742309219a2450527.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论