如何将 Numpy / PyTorch 数组的下 n 个元素设置为某个值?
How to set the next n elements of a Numpy / PyTorch array to some value?
如果我有一个变量 side_inputs
,.shape
为 [48, 161]
。我想将最后的 n
值设置为其他值。
我的另一个变量 side_input
的 .shape
为 [45, 161]
。
我想将 side_inputs
的最后 45 个元素设置为 side_input
:
side_inputs[:45,:] = side_input
但是我得到一个错误:
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
如果我有一个变量 side_inputs
,.shape
为 [48, 161]
。我想将最后的 n
值设置为其他值。
我的另一个变量 side_input
的 .shape
为 [45, 161]
。
我想将 side_inputs
的最后 45 个元素设置为 side_input
:
side_inputs[:45,:] = side_input
但是我得到一个错误:
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