Learn practical skills, build real-world projects, and advance your career
Updated 4 years ago
Pytorch for statisticians
A statistician's approach to the basics of pytorch
- torch.randn
- Compatibility with numpy (np.array <> torch.tensor)
- torch.reshape
- Various statistics on tensor
- torch.mul
# Import torch and other required modules
import torch
torch.randn
Creates a tensor with the specified dimensions filled with values sampled form the standard normal distribution. (mean 0, variance 1)
Useful when you need a quick example, like in the following 4 functions.
# Using desired output size as input
torch.randn(2)
tensor([ 0.2757, -0.5410])
size (int...)
a sequence of integers defining the shape of the output tensor. Can be a variable number of arguments or a collection like a list or tuple.