NumPy ndarray.T | Get View of Transposed Array
Last Updated :
31 Jan, 2024
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.
Syntax
Syntax: ndarray.T
Returns
Examples
Let’s look at how to use the ndarray.T attribute of the Python’s NumPy library.
Example 1
Python3
import numpy as np
arr = np.array([[ 1 , 2 , 3 ], [ 4 , 5 , 6 ]])
transposed_array = arr.T
print (transposed_array)
|
Output
[[1 4]
[2 5]
[3 6]]
Example 2
Python3
import numpy as np
gfg = np.array([[ 1 , 2 , 3 , 4 ], [ 4 , 5 , 6 , 7 ], [ 7 , 8 , 9 , 0 ]])
geeks = gfg.T
print (geeks)
|
Output:
[[1 4 7]
[2 5 8]
[3 6 9]
[4 7 0]]
The ndarray.T attribute finds its use in machine learning applications where input data needs to be formatted in a certain way for further processing.
It does not modify the original array and only returns the view of the transposed array.
Share your thoughts in the comments
Please Login to comment...