0Pricing
Deep Learning Academy · Урок

Поэлементные операции и свёртки

Вычисляйте сумму, среднее и максимум по выбранным осям

«Поэлементные операции и свёртки» — бесплатный урок Deep Learning Academy на CoddyKit. Это урок 2 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения Deep Learning Academy, и твой прогресс синхронизируется между веб-версией и приложением CoddyKit. Курс Deep Learning Academy содержит 4 уроков всего.

Части этого урока еще не переведены и отображаются на английском.

Two Kinds of Operations

Tensor math splits into two families: elementwise ops that keep the shape, and reductions that collapse it down to fewer numbers.

Elementwise Keeps the Shape

An elementwise op applies the same action to every entry independently. Input shape in, same shape out, no mixing between positions.

b = a * 2 + 1
# same shape as a, every element transformed

Pairwise Elementwise Math

With two tensors of equal shape, elementwise ops act position by position. Add matches index to index, multiply does the same.

c = a + b
d = a * b

Math Functions Are Elementwise Too

Functions like torch.relu, exp, and sqrt run elementwise. Each number is transformed on its own, and the tensor keeps its original shape.

r = torch.relu(x)
e = torch.exp(x)

Reductions Collapse Numbers

A reduction combines many values into fewer. Sum, mean, and max fold a whole tensor down, by default to a single scalar.

total = x.sum()
avg = x.mean()

The dim Argument Picks an Axis

Pass dim to reduce along one axis only. The chosen axis disappears while the others stay, so a 2D tensor becomes 1D.

col_sums = x.sum(dim=0)
row_means = x.mean(dim=1)

keepdim Saves the Shape

Set keepdim=True to keep the reduced axis as size 1. That preserved shape is what makes later broadcasting line up cleanly.

m = x.max(dim=1, keepdim=True).values

Mean Needs Floats

mean divides, so it expects floating-point input. Call it on an integer tensor and PyTorch will complain until you cast to float first.

avg = x.float().mean()

argmax Finds the Winner

Sometimes you want the position, not the value. argmax returns the index of the largest entry, which is how a classifier picks its predicted class.

pred = logits.argmax(dim=1)

Chain Them Together

Real code stacks both kinds: an elementwise transform feeds a reduction. Square the errors, then take the mean, and you have mean squared error.

mse = ((pred - target) ** 2).mean()

Pick Shape-Keeping or Shape-Shrinking

The rule of thumb: reach for elementwise when every value should change in place, and reach for a reduction when you need a summary like a total or average.

Quick Check

Can you tell which operation changes a tensor shape?

Recap: Transform vs Summarize

Elementwise ops keep the shape and act per value; reductions like sum and mean collapse it, with dim and keepdim controlling exactly how. 🎯

Часто задаваемые вопросы

Урок «Поэлементные операции и свёртки» бесплатный?

Да — полный текст урока «Поэлементные операции и свёртки» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс Deep Learning Academy, подпишись на CoddyKit PRO. Курс Deep Learning Academy содержит 4 уроков всего.

Чему я научусь в уроке «Поэлементные операции и свёртки»?

Вычисляйте сумму, среднее и максимум по выбранным осям Ты практикуешь Deep Learning Academy с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.

Нужен ли мне опыт, чтобы начать Deep Learning Academy?

Предыдущий опыт не требуется. Deep Learning Academy на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 2 из 4.

Сколько времени занимает урок «Поэлементные операции и свёртки»?

Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.

Можно ли писать и запускать код в этом уроке Deep Learning Academy?

Да. Каждый урок Deep Learning Academy включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.

Все уроки этого курса

  1. Почему циклы медленны в математических вычислениях
  2. Поэлементные операции и свёртки
  3. Умножение матриц с matmul и @
  4. Скалярные произведения обеспечивают работу каждого слоя
← Назад к Deep Learning Academy