Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Challenge: Initializing Tensors | PyTorch Introduction
PyTorch Essentials

book
Challenge: Initializing Tensors

Tehtävä

Swipe to start coding

  1. Create a 2x3 tensor filled with zeros using the appropriate creation function.
  2. Create a 1D tensor with integer values from 1 to 10 inclusive (11 exclusive) using the appropriate creation function.
  3. Create a 1D tensor with 10 evenly spaced values between 2 and 4 inclusive using the appropriate creation function.

Ratkaisu

import torch

# Create a 2x3 tensor filled with zeros
tensor_1 = torch.zeros(2, 3)
# Create a 1D tensor with values from 1 to 10 inclusive
tensor_2 = torch.arange(1, 11)
# Create a 1D tensor with 10 evenly spaced values between 2 and 4
tensor_3 = torch.linspace(2, 4, steps=10)
# Print the tensors
print(tensor_1)
print(tensor_2)
print(tensor_3)
Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 1. Luku 4
import torch

# Create a 2x3 tensor filled with zeros
tensor_1 = ___
# Create a 1D tensor with values from 1 to 10 inclusive
tensor_2 = ___
# Create a 1D tensor with 10 evenly spaced values between 2 and 4
tensor_3 = ___
# Print the tensors
print(tensor_1)
print(tensor_2)
print(tensor_3)
toggle bottom row
some-alt