I have a dict H，which key is（i，j） and value is a tensor of 4 elements.

And a one-dim tensor e, such as e =[1,2,3]

I want to construct a 3-dim tensor T:

T = torch.tensor(H[(e[i] ,e[j])] for i in range(3) for j in range(3)])

that is to say T_ij = H[(e[i],e[j])].

T will be a tensor with size (3,3,4)

is there any possible way to parallel this process?

Thanks very much!!

I don’t quite understand what `H`

is since you are mentioning a `dict`

, but are trying to call it with two indices. Are you using a nested `list`

instead or a tensor?

1 Like

Thanks your reply!

H is a python dictionary，which key is a tuple.

Like H[(0,0)] = [1,2,3,4]

H[(0,1)] = [1,2,3,4]