As the title says I want to calculate the component-wise product of all column combinations of two matrices. I already found a solution using numpy.einsum
and numpy.hstack
. I wonder if there is a solution without hstack
.
Let a = [a_1, a_2, ..., a_n]
be a d x n
matrix and b = [b_1, b_2, ..., b_m]
a d x m
matrix. I want to calculate
[a_1b_1, a_1b_2, ..., a_nb_{n-1}, a_nb_n]
,
where a_kb_l
is the component wise product, i.e. a_kb_l = [a_{1,k}*b{1,l}, ..., a_{d,k}*b{d,l}].T
.
My solution is the following.
np.hstack(np.einsum('...j,...l -> j...l', a, b))
Can I go without the h_stack
?