← Back to NumPy Course | Chapter 7: Linear Algebra | Lesson 5 of 6

Matrix Multiplication (@) ऑपरेटर

@ operator matrices को proper linear-algebra तरीके से multiply करता है।
Syntax
python
result = a @ b
result = np.matmul(a, b)

Matrix Multiplication (@)

Python 3.5 में introduce हुआ, @ np.matmul में map होता है। 2-D arrays के लिए यह standard row-by-column product है। matrices के stacks के लिए यह leading dimensions पर broadcast करता है।

Note: कई products chain करते वक्त A @ B, np.dot(A, B) से clearer है।

उदाहरण: Matrix multiplication (@)

python
import numpy as np

A = np.array([[1, 2], [3, 4]])
B = np.array([[0, 1], [1, 0]])
print(A @ B)
print(B @ A)
print(A * B)

# Output:
# [[2 1]
#  [4 3]]
# [[3 4]
#  [1 2]]
# [[0 2]
#  [3 0]]
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. @ की बजाय * इस्तेमाल करना
  2. Inner dimensions को mismatched रखना
  3. यह मान लेना कि A @ B, B @ A के बराबर है
चैप्टर सारांश
  • @ matrix multiplication है
  • * element-wise है
  • (m, n) @ (n, p) (m, p) देता है
  • Commutative नहीं है
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.