Vectors and Matrixes

Niklas Donges Niklas Donges
July 17, 2019 AI & Machine Learning

Vectors are one of the most crucial concepts within Machine Learning because many bugs are due to having matrix /vector dimensions that don’t fit properly. Therefore it is essential for a machine learning engineer to have a good understanding of it.

Vectors

Let’s say your an engineer at Tesla and you get a dataset of produced cars with 3 features: Length, Width and Height.

Bildschirmfoto 2017-11-07 um 08.14.04

Each of those cars can be represented as a point within a 3-dimensional space.

Bildschirmfoto 2017-11-07 um 08.03.27.png

Datapoints with for example 500 features could be represented within a 500-dimensional space. It is hard for us as humans to imagine more than a 3-dimensional space but computers are very good at it.

A vector is a 1-dimensional array. Think of an vector as a list of values or a row in a table. You could also say that a vector is a matrix but with only one column.

A vector of n-elements is an n-dimensional vector, with one dimension for each element.

So for a 3 dimensional datapoint we could use a 1-by-3 array to hold the 3 features. It represents a set of features, which is why we call it a feature vector.

Matrix

More general than a vector is a matrix. A matrix is a rectangular array of numbers and a vector can be a row or column within a matrix.   

Bildschirmfoto 2017-11-09 um 17.19.16.png

Therefore each row in an array could represent a different datapoint. Less general than a vector is a scalar, because it’s just a single number but that’s another topic. 

The Dimension of a matrix is going to be written as the number of rows times the number of columns. 

To show this more clearly you can see a 4 by 2 matrix below.

Bildschirmfoto 2017-11-09 um 17.20.16

Next let’s talk about how to refer to specific elements of the matrix. Matrix elements are just mean the entries/numbers inside the matrix. The picture below shows you just that. If you got a matrix called A, then A subscript ij is going to refer to the i comma j entry. Meaning the entry is in the I row and the j column.

Bildschirmfoto 2017-11-09 um 17.20.27

Here are some examples for it:

A11 = 1402

A32 = 1437

It is nearly the same with a vector. If you have a vector called A then A1 would be it’s first element, A2 it’s second and so on.

Tensors

The most general term for all of these concepts above is a Tensor because a Tensor is a multidimensional array.

So a first-order tensor would be a vector. A second order tensor is a matrix and third-order tensors and higher are called higher-order tensors.

Bildschirmfoto 2017-11-07 um 08.20.02.png

For an example you could represent a social graph that represents friends of friends as a higher order tensor.

You probably know googles own library called tensor flow that allows you to build a computational graph where tensors can „flow“ trough a series of mathematical operations.

As computational power and the amount of data we have increases we are becoming more capable of processing multi dimensional data.

Vectors are usually represented in a lot of different ways and are also used in a lot of fields like physics and science. For an example in Einsteins theory of relativity the curvature of spacetime is described by a Riemann Curvature Tensor (in an order 4 tensor, a higher-order tensor).

Any type of data can be represented as a vector because it can be broken down into a set of numbers. Examples would be Images, stock-prices, videos, text, audio and so on.

A common problem in machine learning is that a model is not really accepting the data and therefore keeps throwing errors. Often the solution lies in vectorizing the data which means nothing more than reshaping the data into the required dimensions. A model expects tensors of a certain size and therefore you need to reshape your input data so that it is in the right vector space. Vectorization is essentially just a matrix operation.

There is a python library called Numpy that can do this with just a single line of code.

>>> x.reshape(10, 10)

Vectors don’t just represent data. They help us to represent our models too because many machine learning models represent their learnings as vectors. All types of neural networks do this.

Once data is vectorized we can do a lot of things with it. A so called „Word2Vec“ model turns words into vectors  and then we can do mathematical operations with it. We can then for an example see how closely words are connected together by computing the distance between their vectors. An example for it would be that the word Germany is closely related to other wealthy European countries. Word vectors that are similar are likely to be clustered together. Through vectorizing words we are able to capture their semantic meanings numerically.

We compute the distance between two vectors by using the notion of a „vector norm“. A norm is any function that maps vectors to real numbers, that satisfy the following conditions.

Bildschirmfoto 2017-11-07 um 09.42.30

The conditions above mean that the lengths need to be always positive, the length of zero implies zero, scalar multiplication extends lengths in a predictable way and distances add reasonably.

Therefore in a basic vector space the norm of a vector would be it’s absolute value and the distance between two numbers. Like this: 

Bildschirmfoto 2017-11-07 um 09.46.48​

  • Experfy Insights

    Top articles, research, podcasts, webinars and more delivered to you monthly.

  • Niklas Donges

    Tags
    Machine Learning
    © 2021, Experfy Inc. All rights reserved.
    Leave a Comment
    Next Post
    Becoming a Level 3.0 Data Scientist

    Becoming a Level 3.0 Data Scientist

    Leave a Reply Cancel reply

    Your email address will not be published. Required fields are marked *

    More in AI & Machine Learning
    AI & Machine Learning,Future of Work
    AI’s Role in the Future of Work

    Artificial intelligence is shaping the future of work around the world in virtually every field. The role AI will play in employment in the years ahead is dynamic and collaborative. Rather than eliminating jobs altogether, AI will augment the capabilities and resources of employees and businesses, allowing them to do more with less. In more

    5 MINUTES READ Continue Reading »
    AI & Machine Learning
    How Can AI Help Improve Legal Services Delivery?

    Everybody is discussing Artificial Intelligence (AI) and machine learning, and some legal professionals are already leveraging these technological capabilities.  AI is not the future expectation; it is the present reality.  Aside from law, AI is widely used in various fields such as transportation and manufacturing, education, employment, defense, health care, business intelligence, robotics, and so

    5 MINUTES READ Continue Reading »
    AI & Machine Learning
    5 AI Applications Changing the Energy Industry

    The energy industry faces some significant challenges, but AI applications could help. Increasing demand, population expansion, and climate change necessitate creative solutions that could fundamentally alter how businesses generate and utilize electricity. Industry researchers looking for ways to solve these problems have turned to data and new data-processing technology. Artificial intelligence, in particular — and

    3 MINUTES READ Continue Reading »

    About Us

    Incubated in Harvard Innovation Lab, Experfy specializes in pipelining and deploying the world's best AI and engineering talent at breakneck speed, with exceptional focus on quality and compliance. Enterprises and governments also leverage our award-winning SaaS platform to build their own customized future of work solutions such as talent clouds.

    Join Us At

    Contact Us

    1700 West Park Drive, Suite 190
    Westborough, MA 01581

    Email: [email protected]

    Toll Free: (844) EXPERFY or
    (844) 397-3739

    © 2025, Experfy Inc. All rights reserved.