Can you give more information about the error?
Here are some examples and as we can see that these code can work well.
tensor_list = [torch.randn(2, 3) for _ in range(5)]
tensor_list
Out[9]:
[tensor([[-0.6082, -0.9290, -0.4921],
[ 0.3344, -0.9338, -0.8563]]),
tensor([[-0.3530, -0.5673, 2.6954],
[ 1.5262, 2.3859, 0.3481]]),
tensor([[ 0.5392, 0.9646, -1.5962],
[-2.2931, 0.6707, -0.4896]]),
tensor([[-1.3532, -0.5953, 1.6039],
[ 0.2937, 0.3643, 1.3153]]),
tensor([[ 1.1544, 0.7681, -1.0410],
[-0.1305, -0.8855, -0.3516]])]
import functools
functools.reduce(torch.max, tensor_list)
Out[14]:
tensor([[1.1544, 0.9646, 2.6954],
[1.5262, 2.3859, 1.3153]])
max_tensor = tensor_list[0]
for tensor in tensor_list[1:]:
max_tensor = torch.max(max_tensor, tensor)
max_tensor
Out[19]:
tensor([[1.1544, 0.9646, 2.6954],
[1.5262, 2.3859, 1.3153]])