> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Vectors Matrices and Tensors Part 2

> Explains vectors, matrices, and tensors and how multi-dimensional arrays power recommendation systems by representing products, features, users and interactions for richer predictions

Vectors let us compare one attribute at a time — for example, filtering strictly for “blue gym bags.” To combine and compare multiple attributes at once (colour and price, for example), we use matrices.

A matrix is a two-dimensional array (an m-by-n table): each row is an observation (one product), and each column is a feature (type, colour, price, rating, etc.). In mathematical notation we write a matrix as rows of numbers inside square brackets; in code it’s a 2-D array or list of lists.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/1ndeLDstm3GBsOYi/images/Mathematics-for-Computing/Linear-Algebra/Vectors-Matrices-and-Tensors-Part-2/matrix-notation-products-table-explanation.jpg?fit=max&auto=format&n=1ndeLDstm3GBsOYi&q=85&s=827314f0e714cb6dd51bb46fd637c65b" alt="The image shows a matrix notation concept with a table listing products, their types, colors, prices, and ratings. There is also a person standing next to the table, possibly explaining the concept." width="1920" height="1080" data-path="images/Mathematics-for-Computing/Linear-Algebra/Vectors-Matrices-and-Tensors-Part-2/matrix-notation-products-table-explanation.jpg" />
</Frame>

Each row represents one bag and each column represents a feature. For example, Alice has found a light-blue gym bag in the inventory — that corresponds to a single row in the matrix.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/1ndeLDstm3GBsOYi/images/Mathematics-for-Computing/Linear-Algebra/Vectors-Matrices-and-Tensors-Part-2/finding-perfect-bag-matrix-table.jpg?fit=max&auto=format&n=1ndeLDstm3GBsOYi&q=85&s=bbf01163d0039ad2c79dbea0b307f165" alt="The image shows a table titled &#x22;Finding the Perfect Bag With Matrix,&#x22; listing bag attributes like ID, type, color, price, and rating, alongside a person presenting the information." width="1920" height="1080" data-path="images/Mathematics-for-Computing/Linear-Algebra/Vectors-Matrices-and-Tensors-Part-2/finding-perfect-bag-matrix-table.jpg" />
</Frame>

Rather than applying filters one at a time, a matrix lets us combine multiple criteria (e.g., `colour ≈ blue` AND `price ≈ 23`) and run vectorized operations to select matching rows efficiently. This is much faster and more scalable than iterating through each record and applying individual checks.

<Callout icon="lightbulb" color="#1CB2FE">
  In data terms: rows = observations (products), columns = features. A matrix with m rows and n columns is often called an m-by-n matrix.
</Callout>

Simple Python example showing a matrix as a list of rows and filtering by price:

```python theme={null}
# Each row: [id, type, color, price, rating]
products = [
    [1, "backpack", "blue", 23.50, 4.6],
    [2, "gym-bag", "light blue", 22.80, 4.4],
    [3, "duffel", "black", 35.00, 4.7],
]

# Find products priced around $23 (within $1)
result = [row for row in products if abs(row[3] - 23.0) <= 1.0]
print(result)
# Example output:
# [[1, 'backpack', 'blue', 23.5, 4.6], [2, 'gym-bag', 'light blue', 22.8, 4.4]]
```

For richer, context-aware recommendations we extend matrices into tensors. A tensor is a multi-dimensional array — in practice often three or more dimensions. Think of a tensor like a Rubik’s cube: each slice is a matrix, and stacking slices creates additional axes of information.

A common tensor layout in recommendation systems is:

* `users × products × interactions` (or time).
* The interactions axis can enumerate clicks, purchases, ratings, adds-to-cart, or time steps.

These additional dimensions capture user behaviour across multiple modes so models can learn patterns across users, items, and interaction types.

To make the difference clear:

| Representation | Dimensions | Example use                                             |
| -------------: | :--------: | ------------------------------------------------------- |
|         Vector |     1D     | Single user preferences for colours                     |
|         Matrix |     2D     | Products × features (type, colour, price, rating)       |
|         Tensor |     3D+    | Users × Products × Interactions (clicks, ratings, time) |

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/1ndeLDstm3GBsOYi/images/Mathematics-for-Computing/Linear-Algebra/Vectors-Matrices-and-Tensors-Part-2/3d-matrix-product-features-recommendations.jpg?fit=max&auto=format&n=1ndeLDstm3GBsOYi&q=85&s=727ddaecdd112818f956308b7f95bd6d" alt="The image shows a 3D matrix labeled with product features and interactions, alongside a &#x22;You Might Also Like&#x22; section with product recommendations and prices. A person is speaking in the lower-right corner." width="1920" height="1080" data-path="images/Mathematics-for-Computing/Linear-Algebra/Vectors-Matrices-and-Tensors-Part-2/3d-matrix-product-features-recommendations.jpg" />
</Frame>

Applied to Alice: the tensor tracks not only product features but also how Alice interacted with those products (clicked, searched, added to cart, rated). By learning multi-dimensional patterns (e.g., Alice tends to click blue backpacks and rate them highly), recommendation models can surface items she’s likely to buy next — such as backpacks, blue trainers, or gym equipment related to items she viewed.

Because tensors encode richer relationships than flat lists or 2-D matrices, models built on them can make stronger, more personalized predictions. Vectors, matrices, and tensors are therefore core building blocks in search systems, recommendation engines, and many machine-learning models.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/1ndeLDstm3GBsOYi/images/Mathematics-for-Computing/Linear-Algebra/Vectors-Matrices-and-Tensors-Part-2/vectors-matrices-tensors-data-representation.jpg?fit=max&auto=format&n=1ndeLDstm3GBsOYi&q=85&s=ff54c65b5cfb76fceb6547fa2438379e" alt="The image is a presentation slide summarizing the uses of vectors, matrices, and tensors in data representation, alongside a person explaining." width="1920" height="1080" data-path="images/Mathematics-for-Computing/Linear-Algebra/Vectors-Matrices-and-Tensors-Part-2/vectors-matrices-tensors-data-representation.jpg" />
</Frame>

Better-structured, multi-dimensional data leads to smarter systems. When customers find what they need quickly and accurately, conversion and retention improve.

Further reading and resources:

* Python Basics course: [KodeKloud — Python Basics](https://learn.kodekloud.com/user/courses/python-basics)
* Intro to tensors and deep learning: \[Tensor Fundamentals — external resources]

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/mathematics-for-computing/module/d8fa251f-80d2-4813-8b52-ad57051b1dcf/lesson/0e04f682-86d2-47a2-a989-c8d5c1a40f8a" />
</CardGroup>
