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 :
- Start off from the innermost
einsum
call :'ij,kj->ik'
. - Moving out, the second one is :
'ij,jk->ik'
. The first argument in it is the output fromstep#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 secondeinsum
call, which isa
.
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?"