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

本文标签: