我分割了这个数组:
import numpy as np
a=np.array([7,1,2,3,4,5,0])
进入
b=a[a<=2]
c=a[a>2]
或
b=[1,2,0]
c=[7,3,4,5]
然后,我预测 b 和 c:
pred_b=[.9,2.01,.02]
pred_c=[7,3,3.85,5.001]
如果您能让我知道如何获得此内容,我将不胜感激:
d=[7,.9,2.01,3,3.85,5.001,.02]
最佳答案
这是解决您问题的简单方法:
# create an array with the same shape as a
d = np.empty_like(a, dtype=float)
# assign values of pred_b to the slice of indicies of b (like you do in the question snippet)
d[a<=2] = pred_b
d[a>2] = pred_c
关于python - 根据原始索引合并到子数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42343541/