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 يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. لماذا تكون الحلقات بطيئة في العمليات الحسابية
  2. العمليات العنصرية والاختزالات
  3. ضرب المصفوفات باستخدام matmul و@
  4. الضربات النقطية تشغّل كل طبقة
← العودة إلى Deep Learning Academy