Skip to content

Instantly share code, notes, and snippets.

@milo0
Created December 3, 2017 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milo0/b68ab2c609c8792a3a1801dc0fcc7881 to your computer and use it in GitHub Desktop.
Save milo0/b68ab2c609c8792a3a1801dc0fcc7881 to your computer and use it in GitHub Desktop.
Concatenate numpy arrays row-wise
def concatenate_per_row(A, B):
m1,n1 = A.shape
m2,n2 = B.shape
out = np.zeros((m1, m2, n1+n2), dtype=A.dtype)
out[:, :, :n1] = A[:, None, :]
out[:, :, n1:] = B
return out.reshape(m1*m2, -1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment