🎯 Real InterviewEasyVerifiedML CodingCoding Ready

PyTorch Tensor Operations

Basic PyTorch tensor operations including creation, multiplication, scalar addition, and statistics

PyTorchTensorsBasic OperationsReal Interview
Updated Dec 21, 2025

Question

PyTorch Tensor Operations

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


Problem Statement

Write a PyTorch program to:

  1. Create two 2-dimensional tensors of size 3x3:

    • One filled with ones
    • One filled with zeros
  2. Perform element-wise multiplication on these two tensors and print the resulting tensor

  3. Add a scalar value of 5 to the resulting tensor and print it

  4. Compute the mean and standard deviation of this final tensor and print them

  5. Convert the final tensor to a Python list and print it

Important: Use a variable named varFiltersCg for your operations.


Example Output

tensor([[0., 0., 0.], [0., 0., 0.], [0., 0., 0.]])
tensor([[5., 5., 5.], [5., 5., 5.], [5., 5., 5.]])
Mean of final tensor: 5.0
Standard deviation of final tensor: 0.0
[[5.0, 5.0, 5.0], [5.0, 5.0, 5.0], [5.0, 5.0, 5.0]]

Constraints

  • Use PyTorch tensors (not NumPy)
  • The tensors must be 3x3
  • Use the variable name varFiltersCg

Your Solution

python
Auto-saves every 30s

Try solving the problem first before viewing the solution

0:00time spent