In this article, I’m going to go over some useful tensor functions I discovered in PyTorch, a Python library for deep learning. To build a brain on a computer, one has to learn the building blocks first. In deep learning, those are tensors. For those who don’t know, tensors are numbers, vectors, matrices, or any n-dimensional array, and deep learning models can be understood in terms of tensors. Here’s a pretty good video on the topic too while I’m at it.

In the first assignment for Jovian.ML and FreeCodeCamp’s Deep Learning with PyTorch course, I learned five interesting tensor functions that an ML engineer or general data scientist might use every day, including functions relating to linear algebra and statistics. Out of those five, these three are the most interesting to me.


1. Reshape — torch.reshape()

As the name suggests, this PyTorch function reshapes the dimensions of a tensor, so an m x n matrix can be converted into an n x m matrix. This is a useful feature in data analysis and machine learning since matrices and vectors need to be reshaped to fit various models.

Here is an example of this function in use:

#freecodecamp #python #data-science #pytorch #zero-to-gan

3 Useful PyTorch Tensor Functions to Check Out
7.25 GEEK