Hi Chichi!
The short answer is pytorch’s broadcasting.



 chichi:

max_1 = torch.max(tensor_1[:, None, :1], tensor_2[:, :1])
The output is: torch.Size([5, 4, 1])


The arguments to max() have the following shapes:
tensor_1[:, None, :1].shape = torch.Size([5, 1, 1])
tensor_2[:, :1].shape =  torch.Size([4, 1])

When broadcast, the two trailing 1s line up, the middle 1 of the first
argument gets broadcast to match the 4 of the second argument, and
the “missing” 5 in the second argument gets broadcast to match the
leading 5 of the first argument.  Thus your final shape is [5, 4, 1].
Best.
K. Frank