NumPy ndarray.transpose() Method | Find Transpose of the NumPy Array Last Updated : 05 Feb, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report The ndarray.transpose() function returns a view of the array with axes transposed. For a 1-D array, this has no effect, as a transposed vector is simply the same vector.For a 2-D array, this is a standard matrix transpose.For an n-D array, if axes are given, their order indicates how the axes are permuted. If axes are not provided and arr.shape = (i[0], i[1], ... i[n-2], i[n-1]), then arr.transpose().shape = (i[n-1], i[n-2], ... i[1], i[0]).Example Python3 import numpy as np arr = np.array([[5, 6], [7, 8]]) transposed_arr = arr.transpose() print(transposed_arr) Output: [[5 7] [6 8]]SyntaxSyntax : numpy.ndarray.transpose(*axes) Parameters : axes : [None, tuple of ints, or n ints] None or no argument: reverses the order of the axes. tuple of ints: i in the j-th place in the tuple means arr’s i-th axis becomes arr.transpose()’s j-th axis. n ints: same as an n-tuple of the same ints (this form is intended simply as a “convenience” alternative to the tuple form)Return : [ndarray] View of arr, with axes suitably permuted. ExamplesLet's look at some examples to of transpose() method of the NumPy library to find transpose of a ndarray: Example 1 : Python3 # Python program explaining # numpy.ndarray.transpose() function # importing numpy as np import numpy as np arr = np.array([[5, 6], [7, 8]]) gfg = arr.transpose() print( gfg ) Output : [[5 7] [6 8]]Example 2 : Python3 # Python program explaining # numpy.ndarray.transpose() function # importing numpy as np import numpy as np arr = np.array([[5, 6], [7, 8]]) gfg = arr.transpose((1, 0)) print( gfg ) Output : [[5 7] [6 8]] Comment More infoAdvertise with us Next Article NumPy ndarray.__irshift__() | Shift NumPy Array Elements to Right S sanjoy_62 Follow Improve Article Tags : Machine Learning Python-numpy Python numpy-ndarray python Practice Tags : Machine Learningpython Similar Reads NumPy ndarray.T | Get View of Transposed Array The NumPy ndarray.T attribute finds the view of the transposed Array. It can transpose any array having a dimension greater than or equal to 2. It works similarly to the numpy.transpose() method but it is easy and concise to use. SyntaxSyntax: ndarray.T Returns Transpose of given arrayExamplesLet's 1 min read NumPy ndarray.tolist() Method | Convert NumPy Array to List The ndarray.tolist() method converts a NumPy array into a nested Python list. It returns the array as an a.ndim-levels deep nested list of Python scalars. Data items are converted to the nearest compatible built-in Python type. Example Python3 import numpy as np gfg = np.array([1, 2, 3, 4, 5]) print 1 min read Numpy MaskedArray.transpose() function | Python numpy.MaskedArray.transpose() function is used to permute the dimensions of an masked array. Syntax : numpy.ma.transpose(axis) Parameters: axis :[list of ints, optional] By default, reverse the dimensions, otherwise permute the axes according to the values given. Return : [ ndarray] Resultant array 2 min read NumPy ndarray.__irshift__() | Shift NumPy Array Elements to Right The ndarray.__irshift__() method returns a new array where each element is right-shifted by the value that is passed as a parameter. Example Python3 import numpy as np gfg = np.array([1, 2, 3, 4, 5]) # applying ndarray.__irshift__() method print(gfg.__irshift__(2)) Output[0 0 0 1 1] SyntaxSyntax: nd 1 min read NumPy ndarray.__ilshift__() | Shift NumPy Array Elements to Left The ndarray.__ilshift__() method is an in-place left-shift operation. It shifts elements in the array to the left of the number of positions specified. Example Python3 import numpy as np gfg = np.array([1, 2, 3, 4, 5]) # applying ndarray.__ilshift__() method print(gfg.__ilshift__(2)) Output[ 4 8 12 1 min read How to Fix Python "Can't Convert np.ndarray of Type numpy.object_"? When working with NumPy we might encounter the error message "Can't Convert np.ndarray of Type numpy.object_." This error typically arises when attempting to convert or perform the operations on the NumPy array that contains mixed data types or objects that are not supported by the intended operatio 4 min read Like