Skip to content Skip to sidebar Skip to footer

Build Matrix From Blocks

I have an object which is described by two quantities, A and B (in real case they can be more than two). Objects are correlated depending on the value of A and B. In particular I k

Solution 1:

np.einsum lets you simplify the tensordot expression a bit:

result = np.einsum('ij,kl->ikjl',a,b).reshape(-1, na * nb)

I don't think there's a way of eliminating the reshape.

It may also be easier to generalize to more arrays, though I wouldn't get carried away with too many iteration variables in one einsum expression.


Solution 2:

I think finally I have found a solution:

np.kron(a,b)

and then I can compose with

np.kron(np.kron(a,b), c)

Post a Comment for "Build Matrix From Blocks"