I have two matrices A and B. Rather than a full Kronecker product kron(A,B), I would like to Kronecker in a row-by-row fashion. That is, the first row of the resulting matrix should have kron(A[1,:],B[1,:]), the second row kron(A[2,:],B[2,:]), and so on. The two matrices will have the same number of rows of course.
mapslices seems to only accept one item, not two. I think I want something like map(kron,zip(eachrow(A),eachrow(B))) but this does not work. It is also important that the ordering of the columns is the same as what kron(A,B) would produce.
I have a function that works, but when is that ever enough? ![]()
function kronrow(X,Y)
N,K = size(X)
L = size(Y,2)
res = Matrix{Float64}(undef,N,K*L)
for i=1:N
res[i,:] = @views kron(X[i,:],Y[i,:])
end
return res
end
Is there a better way?