Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Introduction to Tensors | Section
Neural Networks and Deep Learning Foundations with PyTorch
Abschnitt 1. Kapitel 2
single

single

bookIntroduction to Tensors

Swipe um das Menü anzuzeigen

What is a Tensor?

You are already familiar with some special cases of tensors:

  • Scalar (0D tensor): a single number, like 5 or 3.14;
  • Vector (1D tensor): a list of numbers, such as [1, 2, 3];
  • Matrix (2D tensor): a 2D grid of numbers, like a table with rows and columns.

Higher-dimensional tensors (3D, 4D, etc.) extend the concept of matrices into additional dimensions. For example, a 3D tensor can represent an image with height, width, and color channels.

While the terminology may seem complex at first, the key idea is that tensors are simply containers for numerical data, much like NumPy arrays.

Tensors in PyTorch vs. NumPy Arrays

PyTorch tensors behave similarly to NumPy arrays in many ways. Additionally, indexing and slicing in tensors work the same way as in NumPy arrays, so we won't cover these topics in this course.

However, PyTorch tensors offer additional advantages, such as:

  • Native support for GPU acceleration;
  • Integration with PyTorch's deep learning modules;
  • Compatibility with autograd, PyTorch's automatic differentiation tool for backpropagation.

Creating Tensors

PyTorch provides several ways to create tensors. One of the most basic approaches is to create a tensor from a list or a NumPy array. The recommended way to do this is by passing the data to the torch.tensor() function:

1234
import torch data = [[1, 2], [3, 4]] tensor = torch.tensor(data) print(tensor)
copy
Aufgabe

Wischen, um mit dem Codieren zu beginnen

Create a 3D tensor directly from a 3D list without storing the list in a separate variable. The tensor can have any dimensions and contain arbitrary elements.

Lösung

Switch to desktopWechseln Sie zum Desktop, um in der realen Welt zu übenFahren Sie dort fort, wo Sie sind, indem Sie eine der folgenden Optionen verwenden
War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 2
single

single

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

some-alt