輸入為行向量
import numpy as np a=np.array([ 1 ,2 ,3 ,4,5,6,7,8,9,10]) b=a[0::2] b=b.reshape(-1, 1) print(b) c=a[1::2] c=c.reshape(-1, 1) print(c) d=np.hstack((b,c)) print(d)
分別取出偶數列和奇數列,轉換為列向量,並拼接
輸入為列向量
import numpy as np a=np.array([[ 1 ,2 ,3 ,4,5,6,7,8,9,10]]).T b=a[0::2] print(b) c=a[1::2] print(c) d=np.hstack((b,c)) print(d)
分別取出偶數行和奇數行,並拼接