Escriu per cercar…

Tensor

Tensors are the fundamental building block of machine learning in PyTorch — learn what they are, how to manipulate them, and how to use them on a GPU.

S'ensenya a
Disseny de nous fàrmacsSimilitud molecularDAW-BIO

Goal of the lesson

By the end of this 3-hour session you should be able to:

  • explain what a tensor is and why machine learning frameworks are built around it,
  • create tensors from Python data, NumPy arrays, and built-in factories,
  • inspect and reshape tensors confidently,
  • write small numerical programs using broadcasting and matrix multiplication,
  • move computation to a GPU,
  • read and write [C, H, W] image tensors and apply simple filters to them.

The tensor is the only data structure deep learning really has. Every model input, every weight, every gradient, every output is a tensor. Spending three hours getting comfortable with them pays off in every chapter that follows.

Suggested timing

BlockTopic
30 minSetup, what a tensor is, scalar/vector/matrix/n-dim
30 minAttributes (shape, dtype, device), factory functions
45 minOperations: arithmetic, broadcasting, matmul, reshape, indexing
30 minNumPy interop and GPU
45 minCapstone — image manipulation with pure tensor ops

Setup

This series targets Windows with uv as the Python project manager.

If you don’t have uv yet, install it from PowerShell:

ps
PowerShell
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

Create the project:

ps
uv init --python 3.12 tensor
cd tensor
uv add torch torchvision matplotlib pillow numpy

Check the install:

python
main.py
import torch

print("torch:", torch.__version__)
print("cuda available:", torch.cuda.is_available())

Estàs llegint una vista prèvia.

Inicia sessió amb Google per llegir la pàgina completa.

Inicia sessió amb Google

Amb qualsevol compte de Google. Només et demanarem que acceptis les condicions del servei.