我正在尝试重写以下代码,
processed_feats[0, 0::feats+2] = current_feats[0, 0::feats]
processed_feats[0, 1::feats+2] = current_feats[0, 1::feats]
processed_feats[0, 2::feats+2] = current_feats[0, 2::feats]
processed_feats[0, 3::feats+2] = current_feats[0, 3::feats]
processed_feats[0, 4::feats+2] = current_feats[0, 4::feats]
processed_feats[0, 5::feats+2] = current_feats[0, 5::feats]
processed_feats[0, 6::feats+2] = 0
processed_feats[0, 7::feats+2] = 0
在哪里
feats = 6
current_feats is a (1,132) numpy array
and the size of processed_feats should be (1,176) and
have the following format [feat1_1,feat2_1...feat6_1,0,0,feat1_2,feat2_2...]
我正在尝试将它变成一行代码或更少的代码行(如果新解决方案的效率低于现有代码,那么我将回到旧方法)。到目前为止,我已经尝试使用 numpy insert
processed_feats = np.insert(current_feats,range(6,len(current_feats[0]),feats+2),0)
但这并没有考虑在数组末尾添加值,我必须使用两个插入命令,因为我需要在每个 feats+2 索引处添加两个 0。
慕的地6264312
尚方宝剑之说
随时随地看视频慕课网APP
相关分类