为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕斯王 2022-08-16 09:46:04
给定这两个 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.


查看完整回答
反对 回复 2022-08-16
  • 1 回答
  • 0 关注
  • 375 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号