Loading...
Create a PyTorch tensor from a nested Python list.
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.
Write a function create_tensor(data) that takes a nested Python list and returns a PyTorch tensor.
Your function must return a PyTorch tensor. The test will convert it to a nested list for comparison.
[[1, 2], [3, 4]]
tensor([[1, 2],
[3, 4]])We use torch.tensor() to convert a Python list directly into a PyTorch tensor