Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
numpy
communitycreator

What is the numpy.ndarray.T() attribute in Python?

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The ndarray.T in Python is used to obtain the transpose of a given array.

Transpose: The transpose of a matrix is the process of interchanging the row of a matrix with the column and vice-versa.

How transpose works

Below is an illustration of how the transpose of an array works.

Taking transpose of an array

Syntax

Let's have a look at the syntax of ndarray.T.

ndarray.T
Syntax for the ndarray.T attribute

Parameter value

The ndarray.T attribute does not take any parameter value.

Return value

The ndarray.T return the array holding the transpose of an input array.

Example

import numpy as np
# creating an input array
myarray = np.array([[1,2,3], [4,5,6]])
# printing the input array
print(myarray)
# implementing the ndarray.T attribute
print(myarray.T)
Implementing the ndarray.T attribute

Code explanation

  • Line 1: We import the numpy module.
  • Line 3: We create an input array, myarray, using the array() function.
  • Line 6: We print the array, myarray.
  • Line 9: We obtain and print the transpose of the input array using the ndarray.T attribute.

RELATED TAGS

python
numpy
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring