Random Matrix Generation with PyTorch

  • Share this:

Code introduction


This function generates a random matrix of a given number of rows and columns using the PyTorch library.


Technology Stack : PyTorch

Code Type : Function

Code Difficulty : Intermediate


                
                    
import torch
import random

def generate_random_matrix(rows, cols):
    """
    Generates a random matrix of given size using torch.
    """
    return torch.randn(rows, cols)                
              
Tags: