Random Matrix Generator

  • Share this:

Code introduction


This function generates a random matrix of specified shape and data type based on the input number of rows and columns.


Technology Stack : NumPy

Code Type : Function

Code Difficulty : Intermediate


                
                    
import numpy as np

def random_matrix(arg1, arg2):
    """
    Generate a random matrix with given shape and data type.
    
    Args:
    arg1 (int): The number of rows in the matrix.
    arg2 (int): The number of columns in the matrix.
    
    Returns:
    numpy.ndarray: A random matrix with shape (arg1, arg2) and specified data type.
    """
    return np.random.rand(arg1, arg2).astype(np.int32)                
              
Tags: