If x denotes a d dimensional column vector and e_i denotes the ith standard basis in the Euclidean space R^d, I would like to compute the following third-order tensor in python in an efficient way:
Here, the circled-cross refers to the tensor outer product. For now I have been relying on the following rather inefficient code:
import numpy as np
from sktensor import ktensor,dtensor
d=5
x= np.random.normal(0,1,(d,1))
z= np.zeros((d,1))
I= np.identity(d)
T1= ktensor([x,x,x])
T2= ktensor([z,z,z])
T3= ktensor([z,z,z])
T4= ktensor([z,z,z])
for j in range(d):
T2 = T2+ ktensor([I(:,j),I(:,j),x]
T3 = T3+ ktensor([I(:,j),x,I(:,j)]
T4 = T4+ ktensor([x,I(:,j),I(:,j)]
T= T1-T2-T3-T4

sktensorfor a start, seems poorly maintained (I can't seem to get it running to compare). You could write this in purenumpyor maybe have a look attensorflow.