我拆分了这个数组:
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]
答案 0 :(得分:1)
逻辑索引也适用于赋值:
android {
compileSdkVersion 25
buildToolsVersion "25"
defaultConfig {
targetSdkVersion 25
}
}
In dependencies
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
compile 'com.android.support:recyclerview-v7:25.1.0'
答案 1 :(得分:1)
以下是您问题的简单解决方案:
# 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