How to do a tensor expand operation?

I want to find a pytorch function which can do the operation as follows:

a=[ [1 2 3], [1,3,4], [2,5,7] ]  #a.shape is 3*3

I want to obttain a expanded tensor as follows:

b=[ [1,2,3], [0,0,0], [1,3,4], [2,5,7], [0,0,0] ] #b.shape is 5*3

What I want to do is to expand the tensor a to a larger tensor b and assign the selected tensor index such as [0,2,3] from a, and fill other index [1,4] with zero.
I have tried to define a large tensor and use torch.tensor.index_copy_ to do this operation, but this need to define a extral tensor, which brings additional storage, can anyone give some other methods to do this?

maybe you can use torch::cat

Thanks, I find torch::cat, but it can’t fill the selected index with zero.

You could just create b as a zero tensor and index it directly:

a = torch.tensor([[1, 2, 3], [1,3,4], [2,5,7]])
b = torch.zeros(5, 3, dtype=torch.long)
b[[0, 2, 3]] = a