Random Matrix Generation with PyTorch

  • Share this:

Code introduction


This function generates a random matrix with a specified number of rows and columns using the torch library.


Technology Stack : PyTorch

Code Type : Function

Code Difficulty : Intermediate


                
                    
import torch
import random

def generate_random_matrix(n_rows, n_cols):
    """
    Generate a random matrix with given number of rows and columns using torch.
    """
    return torch.rand(n_rows, n_cols)                
              
Tags: