'numpy equivalent code of unsqueeze and expand from torch tensor method

I have these 2 tensors

box_a = torch.randn(1,4)
box_b = torch.randn(1,4)

and i have a code in pytorch

box_a[:, 2:].unsqueeze(1).expand(1, 1, 2)

but i want to convert the above code in numpy
for box_a and box_b i can do something like this

  box_a = numpy.random.randn(1,4)
  box_b = numpy.random.randn(1,4)

But what about this

box_a[:, 2:].unsqueeze(1).expand(1, 1, 2)


Solution 1:[1]

solved it

box_a = np.random.randn(1,4)
box_b = np.random.randn(1,4)
max_xy = np.broadcast_to(np.expand_dims(box_a[:, 2:],axis=1),(1,1,2))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Prajot Kuvalekar