0Pricing
Deep Learning Academy · درس

ضرب المصفوفات باستخدام matmul و@

الضربات النقطية الكامنة وراء كل طبقة

ضرب المصفوفات باستخدام matmul و@ درس مجاني في Deep Learning Academy على CoddyKit. هذا هو الدرس 3 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Deep Learning Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Deep Learning Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Beyond Elementwise

Multiplying tensors with the star sign is elementwise. Matrix multiplication is different: it mixes rows and columns into weighted sums.

Dot Products in Bulk

Each output entry of a matrix multiply is a dot product: one row of the left matrix paired with one column of the right matrix.

The Inner Dimensions Must Match

To multiply shapes (m, k) and (k, n), the inner k must agree. The result is (m, n): outer dimensions survive, the inner one is summed away.

The @ Operator

Python gives matrix multiply its own clean symbol. The @ operator multiplies two tensors the matrix way, no loops in sight.

c = a @ b

torch.matmul Does the Same

torch.matmul is the spelled-out twin of @. Same result, handy when you prefer a named function call in your code.

c = torch.matmul(a, b)

Mind the Shapes

A (2, 3) times a (3, 4) gives a (2, 4). Read the shapes left to right and the inner 3 cancels, leaving the outer pair.

a = torch.randn(2, 3)
b = torch.randn(3, 4)
c = a @ b  # shape (2, 4)

Star Is Not At

Do not confuse them: a * b is elementwise and needs matching shapes, while a @ b is matrix multiply and needs matching inner dimensions.

Matrix Times Vector

Multiply a matrix by a 1D vector and you get a vector. Each output number is the dot product of a matrix row with that vector.

y = W @ x  # W is (n, m), x is (m,), y is (n,)

Batched matmul

matmul handles batches: feed shapes (B, m, k) and (B, k, n) and it multiplies each of the B matrix pairs at once, returning (B, m, n).

out = torch.matmul(batch_a, batch_b)

Shape Errors Are Loud

Mismatch the inner dimensions and PyTorch throws a clear RuntimeError. Reading those shape messages quickly becomes your fastest debugging tool.

The Engine of Every Layer

This one operation is everywhere. A linear layer is just inputs times a weight matrix plus a bias, and matmul does that heavy lifting.

out = x @ W.T + bias

Quick Check

Time to check your shape arithmetic.

Recap: Rows Meet Columns

Matrix multiply with @ or torch.matmul pairs rows with columns into dot products; inner dimensions must match, outer ones survive. It powers every layer. 🔗

الأسئلة الشائعة

هل درس «ضرب المصفوفات باستخدام matmul و@» مجاني؟

نعم — نص درس «ضرب المصفوفات باستخدام matmul و@» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Deep Learning Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Deep Learning Academy 4 دروس في المجموع.

ماذا ستتعلم في «ضرب المصفوفات باستخدام matmul و@»؟

الضربات النقطية الكامنة وراء كل طبقة تتمرن على Deep Learning Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Deep Learning Academy؟

لا تُشترط خبرة سابقة. Deep Learning Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 4.

كم من الوقت يستغرق درس «ضرب المصفوفات باستخدام matmul و@»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Deep Learning Academy هذا؟

نعم. كل درس في Deep Learning Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

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

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