在Python中用较小的矩阵制作较大的矩阵 [英] Making bigger matrices out of smaller matrices in Python

查看:541
本文介绍了在Python中用较小的矩阵制作较大的矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在用较小的矩阵制作较大的矩阵时遇到问题.

I have a problem making a bigger matrix out of smaller matrixs.

假设我有矩阵:

      1 2 3
  A=  4 5 6
      7 8 9

      1 0 0 
  B=  0 1 0
      0 0 1

我想要得到的结果是

    1 2 3 1 0 0
C = 4 5 6 0 1 0
    7 8 9 0 0 1

如果我要在MATLab中进行此操作,就像做C = [A B]一样简单

If I'm to do this in MATLab it would be as simple as doing C = [A B]

但是我现在正在使用python.

But I'm working with python at the momment.

一个人怎么能在python中做那件事?

How could one do that thing in python?

顺便说一句,在python中,矩阵A和B将由我的程序生成,它们将是ndarrays(在我的问题上,它们是15000x1626数组或矩阵,如果需要的话).

Btw, in python the matrices A and B would be made by my program and they would be ndarrays (at my problem, they are 15000x1626 arrays, or matrices, if needed to be).

非常感谢您的帮助.

推荐答案

尝试使用 np.hstack :

C = np.hstack((A,B))

np.concanenate :

C = np.concatenate((A,B),axis=1)

这篇关于在Python中用较小的矩阵制作较大的矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆