Find the number of rows and columns of a given matrix using NumPy Last Updated : 05 Mar, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report The shape attribute of a NumPy array returns a tuple representing the dimensions of the array. For a two-dimensional array, the shape tuple contains two values: the number of rows and the number of columns. In this article, let's discuss methods used to find dimensions of the matrix. How to Find the Number of Rows and Columns of a Matrix?We can find matrix dimension with three ways: Using shape AttributeUsing IndexingUsing numpy.reshape()Way 1: Using .shape AttributeHere we are finding the number of rows and columns of a given matrix using Numpy.shape. Python import numpy as np matrix = np.array([[9, 9, 9], [8, 8, 8]]) dimensions = matrix.shape rows, columns = dimensions print("Rows:", rows) print("Columns:", columns) Output: Rows: 2 Columns: 3Way 2: Using IndexingHere we are finding the number of rows and columns of a given matrix using Indexing. Python import numpy as np matrix = np.array([[4, 3, 2], [8, 7, 6]]) rows = matrix.shape[0] columns = matrix.shape[1] print("Rows:", rows) print("Columns:", columns) Output: Rows: 2 Columns: 3Way 3: Using numpy.reshape()Here we are using numpy.reshape() to find number of rows and columns of a matrix, numpy.reshape in NumPy is used for changing the shape of an array without modifying the underlying data. When using np.arange(start, stop), remember that the stop element is not included in the generated array. So, np.arange(1, 10) will create an array with values from 1 to 9 (inclusive). Python import numpy as np matrix= np.arange(1,10).reshape((3, 3)) print(matrix) # Original matrix print(matrix.shape) # Number of rows and columns of the said matrix Output: [[1 2 3][4 5 6][7 8 9]](3,3) Comment More infoAdvertise with us Next Article Find the number of rows and columns of a given matrix using NumPy V vipinyadav15799 Follow Improve Article Tags : Python Python-numpy Python numpy-Matrix Function Practice Tags : python Similar Reads Compute the condition number of a given matrix using NumPy In this article, we will use the cond() function of the NumPy package to calculate the condition number of a given matrix. cond() is a function of linear algebra module in NumPy package. Syntax:Â numpy.linalg.cond(x, p=None) Example 1: Condition Number of 2X2 matrix Python3 # Importing library impor 2 min read How to get the number of dimensions of a matrix using NumPy in Python? In this article, we will discuss how to get the number of dimensions of a matrix using NumPy. It can be found using the ndim parameter of the ndarray() method. Syntax: no_of_dimensions = numpy.ndarray.ndim Approach: Create an n-dimensional matrix using the NumPy package.Use ndim attribute available 3 min read Number of rows and columns in a Matrix that contain repeated values Given a N x N square matrix arr[][] which contains only integers between 1 and N, the task is to compute the number of rows and the number of columns in the matrix that contain repeated values. Examples: Input: N = 4, arr[][] = {{1, 2, 3, 4}, {2, 1, 4, 3}, {3, 4, 1, 2}, {4, 3, 2, 1}} Output: 0 0 Exp 6 min read Get the number of rows and number of columns in Pandas Dataframe Pandas provide data analysts a variety of pre-defined functions to Get the number of rows and columns in a data frame. In this article, we will learn about the syntax and implementation of few such functions. Method 1: Using df.axes() Method axes() method in pandas allows to get the number of rows a 3 min read Count the number of rows and columns of Pandas dataframe In this article, we'll see how we can get the count of the total number of rows and columns in a Pandas DataFrame. There are different methods by which we can do this. Let's see all these methods with the help of examples. Example 1: We can use the dataframe.shape to get the count of rows and column 2 min read Like