You can download this code by clicking the button below.
This code is now available for download.
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)