4 ms·
If you, like me, need to use einsum programmatically you'll find the less-known stringless interface way less cumbersone: e.g. matrix multiplication of A and B:
by ziofill 3y ago
If you, like me, need to use einsum programmatically you'll find the less-known stringless interface way less cumbersone: e.g. matrix multiplication of A and B: `np.einsum(A, [0,1], B, [1,2])`.
- deleted 3y ago[deleted]
- chpatrick 3y agoI think einsum is great but it's a bit like regex in that it's unnecessarily concise and hard to read. I use a wrapper where you can name the axes anything you like, eg. "index", "world", "cam", and it translates it to the single letters. Even better is if the library keeps track of the names of the tensor axes and the einsum is automatic.
- WCSTombs 3y agoI totally agree. Here's a library that basically does that: https://docs.xarray.dev/en/stable/ https://docs.xarray.dev/en/stable/
- rsfern 3y agoNot sure if the wrapper you’re talking about is your own custom code, but I really like using einops lately. It’s got similar axis naming capabilities and it dispatches to both numpy and pytorch http://einops.rocks/ http://einops.rocks/
- chpatrick 3y agoI just made my own function but that sounds great, I'll check it out!
- deleted 3y ago[deleted]
- quietbritishjim 3y agoNote this is only available in the pytorch variant [1], not the original numpy interface that it is based on [2] [1] https://pytorch.org/docs/stable/generated/torch.einsum.html https://pytorch.org/docs/stable/generated/torch.einsum.html [2] https://numpy.org/doc/stable/reference/generated/numpy.einsum.html https://numpy.org/doc/stable/reference/generated/numpy.einsu...