🎯 Real InterviewEasyVerifiedML CodingCoding Ready

PyTorch Statistics

PyTorch tensor creation, reshaping, and computing statistics (mean, std)

PyTorchTensorsReshapeStatisticsReal Interview
Updated Dec 21, 2025

Question

PyTorch Statistics

Difficulty: Easy
Estimated Time: 10-15 minutes
Tags: PyTorch, Tensors, Reshape, Statistics
Source: Real Interview Question


Problem Statement

Write a PyTorch program to:

  1. Create a 1-dimensional tensor of size 10, initialized with integer values from 1 to 10 (inclusive)

  2. Reshape this tensor to a 2-dimensional tensor of size 2x5

  3. Compute and print the mean and standard deviation of the reshaped tensor

  4. Convert the reshaped tensor to a Python list and print it


Example Output

Mean of reshaped tensor: 14.5
Standard deviation of reshaped tensor: 3.0276503562927246
[[10.0, 11.0, 12.0, 13.0, 14.0], [15.0, 16.0, 17.0, 18.0, 19.0]]

Constraints

  • Use PyTorch tensors (not NumPy)
  • Tensor must be reshaped to exactly 2x5
  • Use appropriate PyTorch functions for mean and std

Your Solution

python
Auto-saves every 30s

Try solving the problem first before viewing the solution

0:00time spent