pytor Flashcards
pytorch: To create an integer tensor, type
torch.tensor([1,2,3])
pytorch: To create a float tensor, type
torch.FloatTensor([1,2,3])
pytorch: To reshape an existing tensor by choosing the column and row dimensions, type
my_tensor.view(10, 10)
Note: It will error if the existing tensor does not properly fit into the new shape’s slots.
pytorch: To reshape an existing tensor by choosing the number of columns and then have the row number automatically accommodate it, type
my_tensor.view(10, -1)
pytorch: To create a tensor from a numpy array, type
my array = np.array([1, 2, 3])
my_tensor = torch.from_numpy(array)
pytorch: Adding or multiplying two tensors
applies the operation to only the value in the same index
pytorch: The dot product is when you
multiply two tensors and then sum all the resulting values.
pytorch: To create a tensor for 10 equally spaced numbers between 2 numbers, type
torch.linspace(0, 10)
pytorch: To plot a graph of 2 tensors, type
plt.plot(x.numpy(), v.numpy())
pytorch: To create a 1 dimensional range in pytorch, type
torch.arange(1, 10)
pytorch: To get the dimensions of a tensor, type
my_tensor.dim()
pytorch: To slice a 2 dimensional tensor, type
my_tensor[0, 0]
pytorch: A 3 dimensional array can be imagined as
multiple separate 2 dimensional tables
pytorch: To multiply two tensors matrices, type
my_tensor_matrix_1 @ my_tensor_matrix_2
pytorch: To set the seed, type
torch.manual_seed(1)