Re-assign part of the tensor object

Hi all,

Is there a way to re-assign the batch_size of a tensor?

For example: if I have a tensor x of shape [1,200,1,1], is there a way like x.shape[0] = 20

So it becomes of shape [20,200,1,1]

Any help/suggestion with that, please?


What do you expect this new Tensor to contain?

@albanD it contains a randoms numbers

when you say random you mean truly random or undefined values?

@albanD truly random as been generated previously (before many steps with torch.randn)

The simplest would be to just re-generate it with x = torch.randn(new_size).

@albanD I understand you, but no

this random tensor are not directly generated with torch.randn (it come after a number of calculations of another tensor been generated with torch.randn

But if you want 20 times more samples (as in the example you gave initially), you need to call your code that generates these numbers with the bigger input to get more random numbers.
Or do you want 20 times the same samples?

@albanD Yes exactly, I want 20 times the same samples


x.expand([20,200,1,1]) then :slight_smile:

@albanD Oh it works! :slight_smile:

Many thanks!