Torch tensor with i-th element as product of all previous

You can use torch.cumprod:

import torch

t = torch.tensor([1, 2, 3, 4, 5, 6])
torch.cumprod(t, dim=0)

which outputs:

tensor([1, 2, 6, 24, 120, 720])

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top