Skip to content Skip to sidebar Skip to footer

Is There A Verctorized Approach In Pytorch To Get This Result?

I would like to get this result with torch functions. Do you have suggestions? import torch test_tensor=torch.tensor([[1, 2, 3, 4, 5, 6], [7, 8, 9, 1

Solution 1:

Using standard Python stride notation

import torch
test_tensor=torch.tensor([[1,  2,  3, 4,  5,  6],
                         [7,  8,  9, 10,  11,  12]]
                        )

t1 = test_tensor[:, :3].sum(dim=1)
print(t1)
t2 = test_tensor[:, ::2].sum(dim=1)
print(t2)

Post a Comment for "Is There A Verctorized Approach In Pytorch To Get This Result?"