numpy.random.seed(0)
n = 120
N = 1000
X = numpy.random.random((N, n))
start_time = time.time()
M3 = numpy.einsum('ij,ik,il->jkl', X, X, X)
end_time = time.time()
print(('check:', M3[2, 4, 6], '= 125.401852515?'))
print(('check:', M3[4, 2, 6], '= 125.401852515?'))
print(('check:', M3[6, 4, 2], '= 125.401852515?'))
print(('check:', numpy.sum(M3), '= 218028826.631?'))
print(('total time =', end_time - start_time))
Alternatives to numpy einsum