🔢 Matrix

Last Updated: Jan 2026


A matrix is a rectangular arrangement of numbers in rows and columns.

In programming, matrices are used to:

  • Store structured data
  • Apply transformations
  • Perform fast computations

🗣 Hinglish Tip: Matrix ko 2D array jaisa samjho


Matrix Representation

Form

A = [ 1  2  3
      4  5  6 ]

Form

A = [
    [1, 2, 3],
    [4, 5, 6]
]

Matrix Shape (Order)

Matrix shape is written as:

rows × columns

Example:

  • 2 × 3 → 2 rows, 3 columns

🗣 Hinglish Tip: Shape batata hai matrix kitna bada hai


Matrix Types

1.Row Matrix

[ 1  2  3 ]

2.Column Matrix

[ 1 ]
[ 2 ]
[ 3 ]

3.Square Matrix

Rows = Columns

[ 1  2 ]
[ 3  4 ]

4.Zero Matrix

All elements are zero.


5.Identity Matrix

Diagonal = 1, rest = 0

[ 1  0 ]
[ 0  1 ]

🗣 Hinglish Tip: Identity matrix = matrix ka 1


Matrix Operations

1.Matrix Addition

Same shape required.

[1 2] + [3 4] = [4 6]
[3 4]   [1 2]   [4 6]

2.Scalar Multiplication

2 × [1 2] = [2 4]
    [3 4]   [6 8]

3.Matrix Transpose

Rows become columns.

Aᵀ
[1 2 3]ᵀ = [1]
           [2]
           [3]

Used in:

  • Shape matching
  • Optimization problems

4.Matrix Multiplication

Rule:

(A rows × A columns) × (B rows × B columns)
A columns == B rows

If this rule fails → multiplication not possible.

🗣 Hinglish Tip: Beech ke numbers same hone chahiye

Shape of Result Matrix

(A rows × A columns) × (B rows × B columns)
→ (A rows × B columns)

🗣 Hinglish Tip: Andar wale numbers same hone chahiye

Simple Example

Matrix A:

[ 1  2 ]
[ 3  4 ]

Matrix B:

[ 5  6 ]
[ 7  8 ]

Result:

[ (1×5 + 2×7)   (1×6 + 2×8) ]
[ (3×5 + 4×7)   (3×6 + 4×8) ]