How to find the biggest of two pytorch tensors on size
>>> tensor1 = torch.empty(0)
>>> tensor2 = torch.empty(1)
torch.maximum is returrning the empty tensor as the biggest tensor
Is there a way to find the biggest tensor among two tensors (mostly 1d), base on the number of elements in the tensor.
desires output is
Something like this should work:
idx = torch.argmax(torch.tensor([t.nelement() for t in tensors]))
out = tensors[idx]
tensor1 = torch.empty(0)
tensor2 = torch.empty(1)
tensor3 = torch.empty(10)
maxfunc(tensor1, tensor2, tensor3)
maxfunc(tensor3, tensor1, tensor2)
Thanks @ ptrblck, is there any performance difference if i use len(tensor) or tensor.shape (1d tensor)?
I don’t know if there is an expected performance difference (but you could certainly profile it).
However, these operations are also not used in my code.