Learn practical skills, build real-world projects, and advance your career
Updated 4 years ago
Exploring PyTorch Tensor
Short exploration and explanation of PyTorch Tensor function
An short introduction about PyTorch and about the chosen functions.
torch.logspace
torch.argmin
torch.cat
torch.split
torch.mean
# Import torch and other required modules
import torch
import numpy as np
import matplotlib.pyplot as plt
Function 1 - torch.logspace
The torch.logspace function returns a 1-D tensor of steps
point logarithmically spaced with base
base between basestart and baseend.
Note: torch.linspace
is a linear spacing and torch.logspace
is logarithmic spacing
# Example 1 - working
torch.logspace(start=-1, end=1, steps=5, dtype=torch.int32)
tensor([ 0, 0, 1, 3, 10], dtype=torch.int32)
This example returns a tensor with 5 integers from 10-1 to 101 with logarithmically spaced. Here, the values are rounded since the desired data type is set to an Integer (torch.int32)