You just need to perform the operation on the first measurement of your tensors, which is labeled 0 :
c = tensordot(a, b, axes=(0,0))
This will work as you wish. Also, you do not need a list of axes, because this is just one dimension that you take. With axes([1,2],[2,1]) you cross with the 2nd and 3rd dimensions. If you write it in index notation (Einstein summation convention), this corresponds to c[i,j] = a[i,k,l]*b[j,k,l] , so you shorten the indexes you want to keep .
EDIT: Well, the problem is that the tensor product of two three-dimensional objects is 6d. Because abbreviations are associated with pairs of indices, you cannot get a 3D object using the tensordot operation. The trick is to split your calculation into two parts: first you make tensordot by index to perform the matrix operation, and then you take the diagonal of the tensor to reduce your 4d object to 3d. In one team:
d = np.diagonal(np.tensordot(a,b,axes=()), axis1=0, axis2=2)
In the tensor notation, d[i,j,k] = c[i,j,i,k] = a[i,j,l]*b[i,l,k] .
Mattia
source share