I have a question about einsum ellipsis that I thought would be somewhere on StackExchange for sure, but somehow I can't seem to find.
Essentially I have some code which does lots of matrix and vector contractions using numpy's einsum
. The input is usually some parameters that are then used to create vectors and matrices. The code works well, but now I would like to generalize it so that the input parameters can be scanned over a certain range. The nicest thing to do would be to make them vectors and modify my einsum
expressions such that they accept an arbitrary number of additional dimensions that are simply carried through. This question is to ask if this is possible and if so how.
So in my view, this problem boils down to the following. Say I have an einsum
expression that creates that does some kind of matrix multiplication, e.g.
c = np.einsum('ij,jk->ik', a, b)
Now I want to add an arbitrary number of indices to both a and b and simply add them as extra indices in the final matrix, e.g.
c = np.einsum('ijabc,jkde->ikabcde', a, b)
Now when you only do that for one of either a or b, you can do this easily by an ellipsis
c = np.einsum('ij...,jk->ik...', a, b)
So my question is whether you can have multiple ellipses in an einsum
somehow, e.g.
c = np.einsum('ij...,jk...->ik...', a, b)
This will throw an error of course, but hopefully, it is clear what I mean from the examples.
Does einsum
support this kind of 'multi-ellipsis' notation? Or is there any other way to implement this without looping?
My guess is that there is no such way because one would have to tell einsum
in what order to put the remaining indices, i.e. one would have to label the ellipses somehow.