[Numpy-discussion] speed of array vs matrix
Mon Oct 25 08:48:19 CDT 2010
I have noticed a significant speed difference between the array and the matrix implementation of the dot product, especially for not-so-big matrices.
In : import numpy as np
In : b = np.random.rand(104,1)
In : bm = np.mat(b)
In : a = np.random.rand(8, 104)
In : am = np.mat(a)
In : %timeit np.dot(a, b)
1000000 loops, best of 3: 1.74 us per loop
In : %timeit am * bm
100000 loops, best of 3: 6.38 us per loop
The results for two different PCs (PC1 with windows/EPD6.2-2 and PC2 with ubuntu/numpy-1.3.0) and two different sizes are below:
8x104 * 104x1
PC1 1.74us 6.38us
PC2 1.23us 5.85us
8x10 * 10x5
PC1 2.38us 7.55us
PC2 1.56us 6.01us
For bigger matrices the timings seem to asymptotically approach.
Is it something worth trying to fix or should I just accept this as a fact and, when working with small matrices, stick to array?
More information about the NumPy-Discussion