0Pricing
Deep Learning Academy · レッスン

要素単位の演算とリダクション

選択した軸に沿って合計、平均、最大値を求めます

「要素単位の演算とリダクション」はCoddyKit上の無料Deep Learning Academyレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これは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時間対応のAIチューター)、Deep Learning Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Deep Learning Academyコースには全4レッスンが含まれています。

「要素単位の演算とリダクション」で何を学びますか?

選択した軸に沿って合計、平均、最大値を求めます ブラウザで直接実行するハンズオンコードでDeep Learning Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Deep Learning Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのDeep Learning Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。

「要素単位の演算とリダクション」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このDeep Learning Academyレッスンでコードを書いて実行できますか?

はい。すべてのDeep Learning Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. 計算でループが遅い理由
  2. 要素単位の演算とリダクション
  3. matmulと@による行列積
  4. 内積がすべてのレイヤーを動かす
← Deep Learning Academyに戻る