-
Hi, I could only verify answers to the questions you (mrdbourke) have posted the answers to. While going through the exercise for "00. PyTorch Fundamentals - Exercises", I had some troubles:
Gives the output:
While the author to the question says the answer should be:
I don't know what I am doing wrong, can somebody help me with it? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
From what I can tell, only the values are different, which is likely because of a different manual seed passed onto |
Beta Was this translation helpful? Give feedback.
-
Hi @hashraf96, Your code is so close! The error is only minor. The different results come from calling You generally only need to call it once per code cell. See the changes I've made to your code: import torch
seed = 0
# Only set seed once
torch.manual_seed(seed)
# Create random tensors
tensor_random = torch.rand(7, 7)
tensor_random_second = torch.rand(1, 7)
# Perform matrix multiplication
multiplied = torch.mm(tensor_random, tensor_random_second.T)
multiplied, multiplied.shape
# Print outputs
print(f"Tensor A: ",tensor_random )
print(f"\nTensor B: ",tensor_random_second )
print(f"\nTensor B.T: ",tensor_random_second.T )
print(f"\nTensor A * Tensor B.T: ",multiplied ) |
Beta Was this translation helpful? Give feedback.
Hi @hashraf96,
Your code is so close!
The error is only minor.
The different results come from calling
torch.manual_seed()
more than once in a single code cell.You generally only need to call it once per code cell.
See the changes I've made to your code: