给定这两个 numpy 数组:# Two 2-dim arrays with same row number but differnt columna1 = np.array([[9,9,9,9], [9,9,9,9],[9,9,9,9]], dtype=np.int64)a2 = np.array([[3],[3],[3]], dtype=np.int64)如何将这些数组合并到数组 2 创建第三个数组,如下所示:# Third array with same row numbers as above two arrays but its column number is the sum of column numbers of the above two arrays[[9,9,9,9,3], [9,9,9,9,3], [9,9,9,9,3]]简单来说,如何将列连接到二维数组?
1 回答

慕娘9325324
TA贡献1783条经验 获得超4个赞
import numpy as np
a1 = np.array([[9,9,9,9], [9,9,9,9],[9,9,9,9]])
a2 = np.array([[3],[3],[3]])
print(np.concatenate((a1, a2), axis=1))
https://docs.scipy.org/doc/numpy/reference/generated/numpy.concatenate.html
Join a sequence of arrays along an existing axis.
添加回答
举报
0/150
提交
取消