Learn practical skills, build real-world projects, and advance your career

Assignment 1

A sequential series of interesting functions

PyTorch is a machine learning module for Python. Developed primarily by Facebook for the Python language, it also has C++ interoperability. The library stresses functionality with NumPy and an open source system for deep learning using tape based autodiff.

This document contains a highlight of functions I found of interest on first contact with the library, and will be added to as knowledge of data science grows.

  • f1: from_numpy
  • f2: logspace
  • f3: poisson
  • f4: topk
  • f5: lerp
# Import torch and other required modules
import numpy as np
import torch
## Function 1 - torch.fromnumpy

Demonstrating the interopability of the library, this function converts numpy arrays and matrices to Torch tensors. The expected input is a numpy.ndarray (n-dimensional array) and the output will share the same memory space.
# Example 1 - instantiation
n_array = np.array([0,3,5,7,9])
t_tensor = torch.from_numpy(n_array)
t_tensor
tensor([0, 3, 5, 7, 9])

As can be seen, the output maintains the same dimensions, size, and contents, but has become a tensor.