Learn practical skills, build real-world projects, and advance your career
Updated 4 years ago
Assignment 1
María V. Ortiz
Part of Python Zero to GANs course
REFERENCES:
# Import torch and other required modules
import torch
import numpy as np
Function 1 - torch.reshape(input, shape)
It is used to change the dimensions of tensors.
Returns a tensor with the same data and number of elements as input, but with the specified shape.
# setting the random seed for pytorch
torch.manual_seed(42)
a = torch.randn(9,2)
a, a.shape
(tensor([[ 1.9269, 1.4873],
[-0.4974, 0.4396],
[-0.7581, 1.0783],
[ 0.8008, 1.6806],
[ 0.3559, -0.6866],
[ 0.6105, 1.3347],
[-0.2316, 0.0418],
[-0.2516, 0.8599],
[-0.3097, -0.3957]]), torch.Size([9, 2]))
PyTorch will rearrange tensors so they match the shape that is specified in the tuple