[Numpy-discussion] swaxes(0, 1) 10% faster than transpose on 2D matrix?

2012-01-19 Thread Mark Bakker
Hello List,

I noticed that swapaxes(0,1) is consistently (on my system) 10% faster than
transpose on a 2D matrix.

Any reason why? Any reason why the swapaxes algorithm is not used in
transpose?

Just wondering. Thanks,

Mark
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] swaxes(0, 1) 10% faster than transpose on 2D matrix?

2012-01-19 Thread Keith Goodman
On Thu, Jan 19, 2012 at 1:37 AM, Mark Bakker mark...@gmail.com wrote:

 I noticed that swapaxes(0,1) is consistently (on my system) 10% faster than
 transpose on a 2D matrix.

Transpose is faster for me. And a.T is faster than a.transpose()
perhaps because a.transpose() checks that the inputs make sense? My
guess is that they all do the same thing. It's just a matter of which
function has the least overhead.

I[10] a = np.random.rand(1000,1000)
I[11] timeit a.T
1000 loops, best of 3: 153 ns per loop
I[12] timeit a.transpose()
1000 loops, best of 3: 171 ns per loop
I[13] timeit a.swapaxes(0,1)
100 loops, best of 3: 227 ns per loop
I[14] timeit np.transpose(a)
100 loops, best of 3: 308 ns per loop
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion