Sling Academy
Home/PyTorch/Working with Tensors in PyTorch

Working with Tensors in PyTorch

PyTorch is a popular machine learning framework that uses tensors as its building block data structure. Tensors are similar to arrays or matrices, but they can operate on GPUs, making them useful for deep learning applications.

In this series of tutorials, we will introduce you to tensors in PyTorch, covering topics such as tensor creation, indexing, slicing, and manipulation. We’ll also show you how to use tensors for common machine learning tasks such as linear regression and neural network training. By the end of the series, you’ll have a solid understanding of tensors in PyTorch and be ready to tackle more complex machine learning problems.

To get the most out of this series, you should have a basic understanding of the Python programming language and a strong willingness to learn new things.

1 What are PyTorch tensors?

2 PyTorch: How to create a tensor from a Python list

3 Convert a NumPy array to a PyTorch tensor and vice versa

4 Using manual_seed() function in PyTorch

5 PyTorch: How to compare 2 tensors

6 PyTorch: How to create tensors with zeros and ones

7 Ways to Create Random Tensors in PyTorch

8 PyTorch: How to change the data type of a tensor

9 PyTorch tensor shape, rank, and element count

10 How to Create a Tensor Range in PyTorch

11 PyTorch: Determine the memory usage of a tensor (in bytes)

12 How to Transpose a Tensor in PyTorch

13 Working with the torch.matmul() function in PyTorch

14 PyTorch: How to Find the Min and Max in a Tensor

15 PyTorch: Find the Sum and Mean of a Tensor

16 Using the torch.prod() and torch.cumprod() functions in PyTorch

17 How to Reshape a Tensor in PyTorch (with Examples)

18 PyTorch Tensor.view() method (with example)

19 How to Flatten a Tensor in PyTorch (2 Ways)

20 Stacking Tensors in PyTorch: Tutorials & Examples

21 PyTorch: Squeezing and Unsqueezing Tensors

22 PyTorch: Selecting Elements from a Tensor (3 Ways)

23 PyTorch torch.permute() function

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

25 Generate Zero-Filled Tensors Easily with `torch.zeros()` in PyTorch

26 Creating One-Filled Tensors with `torch.ones()` in PyTorch

27 A Guide to Creating Ranges with `torch.arange()` in PyTorch

28 How to Use `torch.linspace()` for Evenly Spaced Tensors in PyTorch

29 Effortlessly Create Identity Matrices with `torch.eye()` in PyTorch

30 Random Tensor Generation with `torch.randint()` in PyTorch

31 Generating Normal Distribution Tensors with `torch.randn()` in PyTorch

32 How to Set Random Seeds for Reproducibility with `torch.manual_seed()` in PyTorch

33 Adding Tensors the Right Way with `torch.add()` in PyTorch

34 Mastering Element-Wise Multiplication with `torch.mul()` in PyTorch

35 The Ultimate Guide to Matrix Multiplication with `torch.matmul()` in PyTorch

36 How to Concatenate Tensors with `torch.cat()` in PyTorch

37 Reshape Your Data Seamlessly with `torch.reshape()` in PyTorch

38 Transposing Tensors Made Easy with `torch.transpose()` in PyTorch

39 A Deep Dive into Tensor Stacking with `torch.stack()` in PyTorch

40 How to Clone Tensors Using `torch.clone()` in PyTorch

41 Compute the Square Root of Tensors with `torch.sqrt()` in PyTorch

42 Exponential Functions Explained: Using `torch.exp()` in PyTorch

43 A Practical Guide to the Logarithm Function `torch.log()` in PyTorch

44 Harness the Power of `torch.sin()` and `torch.cos()` in PyTorch

45 Activate Your Neural Networks with `torch.relu()` in PyTorch

46 How to Apply the Softmax Function with `torch.softmax()` in PyTorch

47 Understanding the Sigmoid Activation with `torch.sigmoid()` in PyTorch

48 Summing Tensor Elements with `torch.sum()` in PyTorch

49 How to Find the Mean of a Tensor Using `torch.mean()` in PyTorch

50 Discovering Maximum Values with `torch.max()` in PyTorch

51 Find the Indices of the Largest Values with `torch.argmax()` in PyTorch

52 Computing the Norm of a Tensor with `torch.norm()` in PyTorch

53 Element-Wise Equality Checks with `torch.eq()` in PyTorch

54 Mastering Greater-Than Comparisons with `torch.gt()` in PyTorch

55 How to Identify Finite Values Using `torch.isfinite()` in PyTorch

56 An Introduction to Automatic Differentiation with `torch.autograd.grad()` in PyTorch

57 Backpropagation Simplified with `torch.autograd.backward()` in PyTorch

58 A Guide to Checking CUDA Availability with `torch.cuda.is_available()` in PyTorch

59 Move Your Tensors to GPU with `torch.to()` in PyTorch

60 Saving and Loading Models with `torch.save()` and `torch.load()` in PyTorch

61 Counting Tensor Elements with `torch.numel()` in PyTorch

62 How to Disable Gradients with `torch.no_grad()` in PyTorch

63 PyTorch Error: mat1 and mat2 shapes cannot be multiplied

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