Python numpy中np_r和np_c

np.r_是按行连接两个矩阵,就是把两矩阵上下相加,要求行数相等,类似于pandas中的concat()

np.c_是按列连接两个矩阵,就是把两矩阵左右相加,要求列数相等,类似于pandas中的merge()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

import numpy as np

def test():
'''
numpy函数np.c_和np.r_学习使用
'''
data_list1=[4,6,12,6,0,3,7]
data_list2=[1,5,2,65,6,7,3]
data_list3=[1,5,2,65,6,6,8]
print u'np.r_ data_list1和data_list2合并'
print np.r_[data_list1,data_list2]
print u'np.r_ data_list1和data_list3合并'
print np.r_[data_list1,data_list3]


print u'np.c_ data_list1和data_list2合并'
print np.c_[data_list1,data_list2]
print u'np.c_ data_list1和data_list3合并'
print np.c_[data_list1,data_list3]


if __name__=='__main__':
test()