[英]Python Reapt value in specific Index Numpy array
我正在 numpy 中寻找一个函数来重复特定索引处的值
index=3
newvalue=100
values=np.array([1, 2, 3,4,5, 6, 7, 8, 9, 10])
values[0]=newvalue
value[1*index]=newvalue
value[2*index]=newvalue
value[3*index]=newvalue
#result [100, 2, 3,100,5, 6, 100, 8, 9, 100]
有任何想法吗??
您可以像这样在切片中跳过索引并设置您认为合适的值:
index = 3
newvalue = 100
values = np.array([1, 2, 3,4,5, 6, 7, 8, 9, 10])
values[::index] = newvalue
values
# array([100, 2, 3, 100, 5, 6, 100, 8, 9, 100])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.