我有一个9列的numpy数组。我需要能够创建列的子集,然后生成一个只是子集的新数组(例如合并0:3和6:8)。获取单个子集很简单,但我仍然坚持创建一个新数组。
Cmatrix =np.array([ (1, 1, 0, 1, 0, 0, 1, 0, 1),\
(1, -1, 0, 1, 0, 0, -1, 0, -1),\
(1, 0, 1, 0, 0, 1, 1, 0, 1),\
(1, 0, 1, 0, 0, 1, -1, 0, -1),\
(1, 0, 0.5, 0, 0, 0.25, 0, 1, 1),\
(1, 0, 0.5, 0, 0, 0.25, 0, 1, -1),\
(1, 0.5, 0.5, 0.25, 0.25, 0.25, 1, 0, 1),\
(1, 0.5, 0.5, 0.25, 0.25, 0.25, 1, 0, 1),\
(1, -0.5, 0.5, 0.25, -0.25, 0.25, -1, 0, -1),\
(1, -0.5, 0.5, 0.25, -0.25, 0.25, -1, 0, -1)])
答案 0 :(得分:3)
np.hstack((Cmatrix[:, :3], Cmatrix[:, 6:8]))
答案 1 :(得分:3)
Cmatrix =np.array([ (1, 1, 0, 1, 0, 0, 1, 0, 1),\
(1, -1, 0, 1, 0, 0, -1, 0, -1),\
(1, 0, 1, 0, 0, 1, 1, 0, 1),\
(1, 0, 1, 0, 0, 1, -1, 0, -1),\
(1, 0, 0.5, 0, 0, 0.25, 0, 1, 1),\
(1, 0, 0.5, 0, 0, 0.25, 0, 1, -1),\
(1, 0.5, 0.5, 0.25, 0.25, 0.25, 1, 0, 1),\
(1, 0.5, 0.5, 0.25, 0.25, 0.25, 1, 0, 1),\
(1, -0.5, 0.5, 0.25, -0.25, 0.25, -1, 0, -1),\
(1, -0.5, 0.5, 0.25, -0.25, 0.25, -1, 0, -1)]
interesting_cols = range(3) + range(6,8)
new_matrix = Cmatrix[:,interesting_cols]