w3resource
NumPy Exercises

NumPy: Find the number of rows and columns of a given matrix

NumPy: Basic Exercise-26 with Solution

Write a NumPy program to find the number of rows and columns of a given matrix.

Sample Solution :

Python Code :

import numpy as np
m= np.arange(10,22).reshape((3, 4))
print("Original matrix:")
print(m)
print("Number of rows and columns of the said matrix:")
print(m.shape)

Sample Output:

Original matrix:
[[10 11 12 13]
 [14 15 16 17]
 [18 19 20 21]]
Number of rows and columns of the said matrix:
(3, 4)                         

Pictorial Presentation:

NumPy: Find the number of rows and columns of a given matrix.

Python Code Editor:


Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a NumPy program to create a 3x4 matrix filled with values ​​from 10 to 21.
Next: Write a NumPy program to create a 3x3 identity matrix, i.e. diagonal elements are 1, the rest are 0.

What is the difficulty level of this exercise?