SlingAcademy

PyTorch

Learn everything about PyTorch, one of the most deep learning framework these days

Mastering Tensor Creation with `torch.tensor()` in PyTorch

Updated: Dec 15, 2024

PyTorch is a popular open-source machine learning library used for applications such as computer vision and natural language processing. One of the foundation blocks in PyTorch’s ecosystem is the tensor. Understanding how to efficiently......

PyTorch torch.permute() function

Updated: Jul 23, 2023

This concise article is about the torch.permute() function in PyTorch. The fundamentals The torch.permute() function is used to rearrange the dimensions of a tensor according to a given order. For example, if you have a tensor of......

PyTorch: Selecting Elements from a Tensor (3 Ways)

Updated: Jul 23, 2023

This pithy, straightforward article will walk you through three different ways to select elements from a tensor in PyTorch. Without any further ado, let’s get started! Indexing & Slicing You can use the square brackets [ ]......

PyTorch: Squeezing and Unsqueezing Tensors

Updated: Jul 23, 2023

Squeezing and unsqueezing a tensor are two operations that can change the shape of a tensor by adding or removing dimensions of size 1. This concise, straight-to-the-point article is about squeezing and unsqueezing tensors in PyTorch by......

Stacking Tensors in PyTorch: Tutorials & Examples

Updated: Jul 23, 2023

This concise, practical article is about stacking tensors in PyTorch with the torch.stack(), torch.vstack(), and torch.hstack() functions. torch.stack() Syntax & Parameters torch.stack() is a PyTorch function that joins or......

How to Flatten a Tensor in PyTorch (2 Ways)

Updated: Jul 15, 2023

Flattening a tensor in PyTorch means reshaping it into a one-dimensional tensor (1D tensor). This concise, example-based article will show you a couple of different ways to do so. Using the torch.flatten() function This approach......

PyTorch Tensor.view() method (with example)

Updated: Jul 15, 2023

This concise and straight-to-the-point article is about the Tensor.view() method in PyTorch. The fundamentals A view of a tensor is a new tensor that shares the same underlying data with the original tensor but has a different shape......

How to Reshape a Tensor in PyTorch (with Examples)

Updated: Jul 14, 2023

Overview In PyTorch, reshaping a tensor means changing its shape (the number of dimensions and the size of each dimension) while keeping the same data and the number of elements. It is useful for manipulating the data to fit......

PyTorch RuntimeError: mean(): could not infer output dtype

Updated: Jul 09, 2023

When working with PyTorch and using the torch.mean() function (or the torch.Torch.mean() method), you might encounter the following error: RuntimeError: mean(): could not infer output dtype. Input dtype must be either a floating point......

PyTorch: Find the Sum and Mean of a Tensor

Updated: Jul 08, 2023

In PyTorch, to find the sum and mean of a tensor, you can use the torch.sum() and torch.mean() functions, respectively. These functions can operate on the whole tensor or on a specific dimension, and return either a single value or a......