Instagram
youtube
Facebook
Twitter

Compute the Rank of a NumPy Array

   Compute the Rank of a NumPy Array
     
     Short Description of the Program:

     This program calculates the rank of a NumPy array using the np.linalg.matrix_rank() function.
     
      Explanation:

  • np.array()
    Creates a 2D matrix (array).

     
  • np.linalg.matrix_rank(array)
    Returns the rank of the matrix — i.e., the number of linearly independent rows or columns.

     
  • print()
    Outputs both the matrix and its rank.

     

Program:

import numpy as np

array = np.array([[10, 20, 10],

                  [20, 40, 20],

                  [30, 60, 15]])

rank = np.linalg.matrix_rank(array)

print("Original Array:\n", array)

print("\nRank of the Array:", rank)