I have a 4D tensor ‘T’ which is of size [d,d,d,d] and two vectors ‘u’ and ‘v’ which are of size [d,1]. I want to compute the following sum in a smarter way:
for i in range(d):
for j in range(d):
for k in range(d):
for l in range(d):
sum += T[i,j,k,l]*u[i]*u[j]*v[k]*v[l]
Can someone help me with this?