Week 8 &9 Flashcards

(4 cards)

1
Q

Question 1: Tensor Creation

Create a PyTorch tensor from the following list of lists and determine its properties:

data = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

  1. Create a tensor from data.
  2. What is the dimension (ndim) of the tensor?
  3. What is the shape (size()) of the tensor?
A
  1. tensor = torch.tensor(data)
  2. Dimension: 2
  3. Shape: torch.Size([3, 3])
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Question 2: Random Tensor Generation

Generate a random tensor and explain its properties:

Write PyTorch code to create a 4x2 tensor filled with random numbers from a uniform distribution between 0 and 1. Then, state:

The shape of the tensor.

The data type of the tensor.

A

Answer:

tensor = torch.rand(4, 2)

Shape: torch.Size([4, 2])

Data type: torch.float32

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Question 3: Tensor Operations

Perform the following tensor operation and compute the result:

Given two tensors:

a = torch.tensor([[1, 2], [3, 4]])
b = torch.tensor([[0, 1], [2, 3]])

Compute a + b and store the result in a new tensor result. What is the value of result?

A

Answer:

result = torch.add(a, b)

Value of result:

tensor([[1, 3],
[5, 7]])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly