猿问

如何合并两个行数相同但列数不同的 numpy 数组

给定这两个 numpy 数组:


# Two 2-dim arrays with same row number but differnt column

a1 = 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]]

简单来说,如何将列连接到二维数组?


慕斯王
浏览 376回答 1
1回答

慕娘9325324

import numpy as npa1 = 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.htmlJoin a sequence of arrays along an existing axis.
随时随地看视频慕课网APP

相关分类

Python
我要回答