Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
copyto = zeros(10) what = ones(3) where = 2 copyto[where:len(what)+where] = what
有没有办法将所有值从较小的数组复制到特定位置的较大数组中,而不提供上索引?我认为它会起作用的方式是
copyto[where:] = what
但这给了我
ValueError: operands could not be broadcast together with shapes
谢谢!
在赋值的左侧和右侧,您必须具有相同形状的数组,以便各个元素之间存在一对一的对应关系。在您的情况下,数组(视图)copyto[where:]有 8 个元素,而what有 3 个元素,因此您的分配没有明确定义。(或者换一种说法:没有唯一的方法可以将三个值分配给八个变量,因此分配定义不明确。)
copyto[where:]
what