Halloween Sale: Flat 70% + Addl. 25% Off + 30 Days Extra Lab on all Courses | Use Coupon HS25 in Checkout | Offer Expires In

  Enroll Now

Numpy - Mathematical and Statistical functions on NumPy Arrays - Transpose

Transpose of a matrix (with rank >= 2) interchanges the rows and columns of the matrix.

We can get the transpose of a matrix (or array) by using the attribute T.

import numpy as np

M = np.arange(6).reshape(2, 3)


The output will be

array( [ [0, 1, 2],
         [3, 4, 5] ] )

Now let us perform the transpose on M

print("Transpose = ", M.T)

The output will be

array( [ [0, 3],
         [1, 4],
         [2, 5] ] )

Please follow the below steps:

(1) Please import the required libraries

  import numpy as np

(2) Please create a Numpy array called N of size 6 and shape as (3,2)

<<your code comes here>> = np.arange(<<your code comes here>>).reshape(<<your code comes here>>)

(3) Print array N using the print() function to see its values

print(<<your code comes here>>)

(4) Print the transpose of array N

print("Transpose = ", <<your code comes here>>)

No hints are availble for this assesment

Answer is not availble for this assesment

Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...