a = np.arange(10) # Input array
idx = np.array([0,1,2]) # Indices to be set
offset = 1 # Offset
a[np.in1d(np.mod(np.arange(a.size),5) , idx+offset)] = 100
使用原始样本进行采样-
^{pr2}$
使用non-sequential indices-
In [851]: a = np.arange(11) # Input array
...: idx = np.array([0,2,3]) # Indices to be set
...: offset = 1 # Offset
...:
In [852]: a[np.in1d(np.mod(np.arange(a.size),5) , idx+offset)] = 100
In [853]: a
Out[853]: array([ 0, 100, 2, 100, 100, 5, 100, 7, 100, 100, 10])
如果重复偏移除以数组长度:
一般情况下需要两行:
^{pr2}$工作原理:以所述方式对数组的连续拉伸进行整形,使目标子串对齐,因此可以使用标准二维索引一次性解决:
这里有一个使用^{} -
使用原始样本进行采样-
^{pr2}$使用
non-sequential indices
-以下是基于您所做工作的另一个解决方案:
它返回:
^{pr2}$相关问题 更多 >
编程相关推荐