简体   繁体   English

如何将 Numpy / PyTorch 数组的下 n 个元素设置为某个值?

[英]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] .如果我有一个变量side_inputs ,其.shape[48, 161] I want to set the last n values to some other value.我想将最后n值设置为其他值。

My other variable, side_input has a .shape of [45, 161] .我的另一个变量side_input.shape[45, 161]

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

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]
side_inputs[:-45, :] = side_input

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM