You can download this code by clicking the button below.
This code is now available for download.
This function generates a random tensor with a specified shape and data type.
Technology Stack : PyTorch
Code Type : Function
Code Difficulty : Beginner
import torch
import random
def generate_random_tensor(shape, dtype=torch.float32):
"""
Generates a random tensor with a given shape and data type.
"""
return torch.randn(*shape, dtype=dtype)