[英]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.