Home:ALL Converter>N-dimensional tensordot equivalent to einsum

N-dimensional tensordot equivalent to einsum

Ask Time:2019-09-19T22:55:55         Author:Saxodrum

Json Formatter

I am trying to find an the tensordot equivalent of the full reduction of two rank-N tensors of equal shape to a scalar via einsum. Both tensors are uniformly of order 3. I want to implement this with tensordot because I think it is easier to scale into higher dimensions. Here are the contractions with einsum up to 4D.

val_1D = np.einsum('i,i', A, B) #1D (aka dot-product)
val_2D = np.einsum('ij,ij', A, B) #2D
val_3D = np.einsum('ijk,ijk', A, B) #3D
val_4D = np.einsum('ijkl,ijkl', A, B) #4D

I need a way to make the N-th contraction without writing all of them out in the code as N can be quite large, and have multiple arrays to perform this on. As far as I understand tensordot this should be possible.

Author:Saxodrum,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/58013831/n-dimensional-tensordot-equivalent-to-einsum
yy