Python中多个数组行合并及列合并的方法总结

import numpy as np

# 创建数组
a = [[1,2,3],[4,5,6]]
b = [[1,1,1],[2,2,2]]

# 数组纵向合并
c = np.vstack((a,b))
c = 
array([[1, 2, 3],
    [4, 5, 6],
    [1, 1, 1],
    [2, 2, 2]]

c = np.r_[a,b]
c = array([[1, 2, 3],
    [4, 5, 6],
    [1, 1, 1],
    [2, 2, 2]])

# 数组横向合并

d = np.hstack((a,b))
d = array([[1, 2, 3, 1, 1, 1],
    [4, 5, 6, 2, 2, 2]])

d = np.c_[a,b]
d = array([[1, 2, 3, 1, 1, 1],
    [4, 5, 6, 2, 2, 2]])

来自:https://www.jb51.net/article/138137.htm

你可能感兴趣的:(实用,python,numpy)