Max on a python list while each item is a variable

Hi guys,

I met a problem about torch.max(). In my forward method, I construct a python list and each item is a Variable. How can I get the maximum of this list?


The input of forward() is several vectors with different size. By some operations with different params, I convert each vector into one number. All those numbers compose a list and I want to return the maximum number of this list.

Any help is appreciated!

What is exact type of element in your list? Does builtin python max works for your?

Each element is a Variable in pytorch

1 Like

Can you do a simple max([ for x in list])?

Yes, that’s exactly how I implement it. However, I think it’s not so elegant. So I want to find if there is any better way to solve it.