python中一向量,每隔一个取向量的数,也就是取向量中的序号是偶数或者奇数的值

输入为行向量

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)

分别取出偶数行和奇数行,并拼接

 

posted @ 2020-06-06 05:32  青女素娥  阅读(1171)  评论(0编辑  收藏  举报