我想将一个小数组复制到特定长度的数组
Example:
var = [22,33,44,55] # ==> len(var) = 4
n = 13
我想要的新数组是:
var_new = [22,33,44,55,22,33,44,55,22,33,44,55,22]
这是我的代码:
import numpy as np
var = [22,33,44,55]
di = np.arange(13)
var_new = np.empty(13)
var_new[di] = var
我收到错误消息:
DeprecationWarning:分配将来会引发错误,很可能是因为您的索引结果形状与值数组形状不匹配。您可以使用arr.flat[index] = values
保持旧的行为。
但我得到了相应的变量:
var_new
array([ 22., 33., 44., 55., 22., 33., 44., 55., 22., 33., 44.,
55., 22.])
那么,如何解决该错误呢?还有其他选择吗?
See also Repeat list to max number of elements https://stackoverflow.com/questions/39863250 for general methods not specific to Numpy.
See also Circular list iterator in Python https://stackoverflow.com/questions/23416381 for lazy iteration over such data.