PIXELBANKv8.2.1
Menu

Create Tensor from List

Problem Statement

Create a PyTorch tensor from a nested Python list.

Background

Tensors are the fundamental data structure in PyTorch. They are similar to NumPy arrays but can run on GPUs. Creating tensors from Python lists is the most basic operation.

Your Task

Write a function create_tensor(data) that takes a nested Python list and returns a PyTorch tensor.

Output Format

Your function must return a PyTorch tensor. The test will convert it to a nested list for comparison.

Example:

Input:
[[1, 2], [3, 4]]
Output:
tensor([[1, 2],
        [3, 4]])
Reasoning:

We use torch.tensor() to convert a Python list directly into a PyTorch tensor

Constraints:

  • Input will always be a valid nested list of numbers
  • The inner lists will all have the same length
  • Values will be integers between -1000 and 1000
Editor

Test Results

0/0
Run code to see test results.