Shamoon
Shamoon

Reputation: 43501

How to set the next n elements of a Numpy / PyTorch array to some value?

If I have a variable side_inputs, with .shape of [48, 161]. I want to set the last n values to some other value.

My other variable, side_input has a .shape of [45, 161].

I want to set the last 45 elements of side_inputs to side_input with:

side_inputs[:45,:] = side_input

But I get an error:

RuntimeError: The expanded size of the tensor (48) must match the existing size (45) at non-singleton dimension 0.  Target sizes: [48, 161].  Tensor sizes: [45, 161]

Upvotes: 0

Views: 88

Answers (1)

Cristian Contrera
Cristian Contrera

Reputation: 713

side_inputs[:-45, :] = side_input

Upvotes: 1

Related Questions