Random Tensor Generator

  • Share this:

Code introduction


This function generates a random tensor with the specified shape and data type.


Technology Stack : torch

Code Type : Function

Code Difficulty : Intermediate


                
                    
import torch
import random

def generate_random_tensor(shape, dtype=torch.float32):
    """
    Generates a random tensor with the specified shape and data type.
    """
    return torch.randn(*shape, dtype=dtype)                
              
Tags: