gpt4 book ai didi

python - 根据原始索引合并到子数组

转载 作者:行者123 更新时间:2023-12-01 03:17:23 24 4
gpt4 key购买 nike

我分割了这个数组:

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com