numpy.ndarray.transpose#

method

ndarray.transpose(*axes)#

Returns a view of the array with axes transposed.

Refer tonumpy.transpose for full documentation.

Parameters:
axesNone, tuple of ints, orn ints
  • None or no argument: reverses the order of the axes.

  • tuple of ints:i in thej-th place in the tuple means that thearray’si-th axis becomes the transposed array’sj-th axis.

  • n ints: same as an n-tuple of the same ints (this form isintended simply as a “convenience” alternative to the tuple form).

Returns:
pndarray

View of the array with its axes suitably permuted.

See also

transpose

Equivalent function.

ndarray.T

Array property returning the array transposed.

ndarray.reshape

Give a new shape to an array without changing its data.

Examples

>>>importnumpyasnp>>>a=np.array([[1,2],[3,4]])>>>aarray([[1, 2],       [3, 4]])>>>a.transpose()array([[1, 3],       [2, 4]])>>>a.transpose((1,0))array([[1, 3],       [2, 4]])>>>a.transpose(1,0)array([[1, 3],       [2, 4]])
>>>a=np.array([1,2,3,4])>>>aarray([1, 2, 3, 4])>>>a.transpose()array([1, 2, 3, 4])
On this page