from datetime import datetime as time
a = np.random.randn(10000, 64, 8)
b = np.random.randn(8, 100)
t1 = time.now()
res1 = np.dot(a, b)
t2 = time.now()
res2 = np.zeros((10000, 64, 100))
for i in range(len(a)):
res2[i] = a[i].dot(b)
t3 = time.now()
print('With loop: {}\nWithout: {}'.format((t3 - t2).total_seconds()*1000, (t2 - t1).total_seconds()*1000))
>>>With loop: 562.9920000000001
>>>Without: 2124.908
I chose the dimensions randomly, but they show the difference. Why is it so huge? Also as I increase dimensionality of arrays it only grows. With small dimensions np.dot without loop shows better perfomance than it does with one.