当前位置:网站首页>Consolidation of common functions of numpy Library

Consolidation of common functions of numpy Library

2022-06-22 13:36:00 A hundred years of literature have been written on the left sid

One 、 Horizontal consolidation and vertical consolidation

1 Horizontal merger

There are already two matrices A and B
If you add two matrices left and right, it becomes [A B], So use numpy.c_, Be similar to pandas In the library merge()

import numpy as np
#A
#1 2 3
#4 5 6
A = np.array([[1,2,3],[4,5,6]])
#B
#11 12
#13 14
B = np.array([[11,12],[13,14]])
#C
#1 2 3 11 12
#4 5 6 13 14
C = np.c_[A, B]

2 Vertical merger

There are already two matrices A and B
If you want to add two matrices up and down, it becomes
[A
B], So use numpy.r_, Be similar to pandas In the library concat()

import numpy as np
#A
#1 2 3
#4 5 6
A = np.array([[1,2,3],[4,5,6]])
#B
#11 12 13
B = np.array([[11,12,13]])
#C
#1 2 3
#4 5 6
#11 12 13
C = np.r_[A, B]
原网站

版权声明
本文为[A hundred years of literature have been written on the left sid]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206221137547945.html