[Numpy-discussion] transpose function

Robert Cimrman cimrman3 at ntc.zcu.cz
Tue Feb 14 05:16:01 CST 2006

Just now I have stumbled on a non-intuitive thing with the transpose 

The help says:
Help on function transpose in module numpy.core.oldnumeric:
transpose(a, axes=None)
     transpose(a, axes=None) returns array with dimensions permuted
     according to axes.  If axes is None (default) returns array with
     dimensions reversed.

There are many functions in scipy that accept the 'axis' argument which 
is a single integer number. I have overlooked that here it is 'axes' and 
see what happens (I expected 'flipping' the array around the given 
single axis, well...):

import scipy as nm

In [26]:b = nm.zeros( (3,4) )
In [27]:b
array([[0, 0, 0, 0],
        [0, 0, 0, 0],
        [0, 0, 0, 0]])

In [29]:nm.transpose( b, 0 )
Out[29]:array([0, 0, 0])

In [30]:nm.transpose( b, 1 )
Out[30]:array([0, 0, 0, 0])

So I propose either to replace 'axes' with 'order' or give an example in 
the docstring. It would be also good to raise an exception when the 
length of the 'axes' argument does not match the array rank and/or does 
not contain a permutation (no repetitions) of relevant indices.

What do the gurus think?


More information about the Numpy-discussion mailing list