Challenge: Initializing Tensors
Tehtävä
Swipe to start coding
- Create a
2x3
tensor filled with zeros using the appropriate creation function. - Create a 1D tensor with integer values from
1
to10
inclusive (11
exclusive) using the appropriate creation function. - Create a 1D tensor with
10
evenly spaced values between2
and4
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ää?
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)