I have two matrices A and B with an equal amount of columns but generally an unequal amount of rows. I want to add up all pairs of columns from matrix A and B. A naive implementation with a for-loop is this:
import numpy as np
ncol = 3
nrow_A = 5
nrow_B = 10
A = np.ones((nrow_A,ncol))
B = np.zeros((nrow_B,ncol))
C = np.empty((nrow_A*nrow_B,ncol))
k = 0
for i in range(nrow_A):
for j in range(nrow_B):
C[k,:] = A[i,:]+B[j,:]
k += 1
which in this example returns a 50*3 matrix filled with ones. It feels like this should be possible with a single line of code. How can I achieve this?