Skip to content

00. PyTorch Fundamentals - Exercises #108

Answered by mrdbourke
hashraf96 asked this question in Q&A
Discussion options

You must be logged in to vote

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:

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"

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@mrdbourke
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by mrdbourke
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants