Kamran Mushtaq
Back to AI & LLM
AI & LLM

Matrix

Added: August 12, 2026

Definition

A matrix is a two-dimensional arrangement of values organized into rows and columns.

Its role is to organize data where both dimensions have meaning.

Example:

Math English Ali 80 70 Sara 90 85

Here:

  • Row → student
  • Column → subject
  • Value → marks

So matrix[Sara][English] = 85.

The Problem That Led to It

An ordinary array works well when you have one dimension:

[80, 90, 70]

But imagine storing marks for many students across many subjects.

You need two dimensions:

Student × Subject

A simple array becomes difficult to organize and query.

The matrix provides that structure.

What Problem It Solves

It lets us represent information where we need:

Row + Column → Value

This becomes especially useful for things like:

  • Images → rows/columns = pixel positions
  • Spreadsheets → rows/columns = records/attributes
  • Networks → rows/columns = source/destination nodes

What Happens If Not Used

You could still store the information using arrays or other structures, but representing relationships between two dimensions becomes less natural.

Easy Wording

A matrix is basically a 2D array where the row and column positions give meaning to each value.

Layman Example

Think of a school timetable:

Mon Tue Wed Math ✓ ✗ ✓ English ✗ ✓ ✓ Physics ✓ ✓ ✗

One dimension = day.

Other dimension = subject.

Technical Example

For our future network:

    A  B  C

A 0 1 1 B 1 0 0 C 1 0 0

Row = source node.

Column = destination node.

Value = connection.

Limitation

A normal matrix stores every position, even when many positions contain 0.

For a huge network, that wastes enormous memory.

Solution

Sparse Matrix solves that problem by focusing on the relatively few values that actually contain useful information.