我正在嘗試重寫以下代碼,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] = 0processed_feats[0, 7::feats+2] = 0在哪里feats = 6current_feats is a (1,132) numpy arrayand 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...]我正在嘗試將它變成一行代碼或更少的代碼行(如果新解決方案的效率低于現(xiàn)有代碼,那么我將回到舊方法)。到目前為止,我已經(jīng)嘗試使用 numpy insertprocessed_feats = np.insert(current_feats,range(6,len(current_feats[0]),feats+2),0)但這并沒有考慮在數(shù)組末尾添加值,我必須使用兩個(gè)插入命令,因?yàn)槲倚枰诿總€(gè) feats+2 索引處添加兩個(gè) 0。
將均勻間隔的值插入 numpy 數(shù)組
慕的地6264312
2023-02-12 19:10:58