0

I have two matrices, A and B. A and B are each 100 x 100. I am trying to produce a combined matrix AB such that is 200 x 100 with the elements of A in the first 100 x 100 and the elements of B in the second 100 x 100.

I tried doing the following, but it says the shape is (2, 1, 500, 500) when I do this in Python.

def get_bigAB(n, lamb):
    return np.array([[A], [get_B(n, lamb)]])

My entries are floats, not simple integers.

My get_B function performs as expected, and of course, I am using Python 3.

324
  • 702
  • 8
  • 28
  • Does this answer your question? [Append a NumPy array to a NumPy array](https://stackoverflow.com/questions/9775297/append-a-numpy-array-to-a-numpy-array) – Björn Apr 07 '20 at 13:46

3 Answers3

1

Using np.vstack ended up working. Thanks for helping!

def get_Alambda(n, lamb):
    B = get_lambdaI(n, lamb)
    AB = np.vstack((A, B))
    return AB
324
  • 702
  • 8
  • 28
0

Have you tried numpy concatenate

import numpy as np
AB = np.concatenate((A,B),axis=0)
print(AB)
print(AB.shape)
Björn
  • 1,610
  • 2
  • 17
  • 37
  • This gets me TypeError: concatenate() got multiple values for argument 'axis' ``` def get_Alambda(n, lamb): B = get_lambdaI(n, lamb) AB = np.concatenate(A, B, axis = 0) return AB print(get_Alambda(n = 500, lamb = 10e-06)) ``` – 324 Apr 07 '20 at 13:50
  • could you provide some more information of what type the matrices are? It would be best to also include your data as in [a minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) – Björn Apr 07 '20 at 13:55
0

Try using vstack(A, B) where matrix B is appended to the bottom of matrix A. This will give you the dimensions you want.