Skip to content Skip to sidebar Skip to footer

Numpy Composition Of Einsums?

Suppose that I have a np.einsum that performs some calculation, and then pump that directly into yet another np.einsum to do some other thing. Can I, in general, compose those two

Solution 1:

In single einsum call, it would be -

np.einsum('ij,kj,kl->il',b,a,a)

The intuition involved would be :

  1. Start off from the innermost einsum call : 'ij,kj->ik'.
  2. Moving out, the second one is : 'ij,jk->ik'. The first argument in it is the output from step#1. So, let's mould this argument for the second one based on the output from the first one, introducing new strings for new iterators : 'ik,kl->il'. Note that 'kl' is the second arg in this second einsum call, which is a.

Thus, combining, we have : 'ij,kj,kl->il' with the inputs in the same sequence, i.e. b,a for the innermost einsum call and then a incoming as the third input.

Post a Comment for "Numpy Composition Of Einsums?"