Suppose I have a matrix X, with n columns. I want to create a new matrix, Y such that each column of Y is a product of two different columns of X.
Currently, I am doing a loop, something like this (not my actual code, but captures the essence of the code):
Y = np.array(X.shape[0], int(n * (n-1)/2))
cnt = 0
for j1 in range(0, n-1):
for j2 in range(j1+1, n):
Y[:, cnt] = X[:, j1] * X[:, j2]
cnt += 1
I was wondering if anyone knows if there is a faster way to generate (populate) matrix Y than the double loop that I am doing ? For instance, any function in numpy that be re-used to generate such a matrix quickly ?