What does unsqueeze do in pytorch?
lower_bounds = torch.max(set_1[:, :2].unsqueeze(1), 
                         set_2[:, :2].unsqueeze(0))   #(n1, n2, 2)

This code snippet uses unsqueeze(1) for one tensor, but unsqeeze(0) for another. What is the difference between them?

unsqueeze turns an n-dimensionsal tensor into an n+1-dimensional one, by adding an extra dimension of zero depth. However, since it is ambiguous which axis the new dimension should lie across (i.e. in which direction it should be &quot;unsqueezed&quot;), this needs to be specified by the dim argument.
Hence the resulting unsqueezed tensors have the same information, but the indices used to access them are different.
Here is a visual representation of what squeeze/unsqueeze do for an effectively 2d matrix, where it is going from a 2d tensor to a 3d one, and hence there are 3 choices for the new dimension's position:

