Over a million developers have joined DZone.

Visualizing Matrix Multiplication as a Linear Combination

DZone's Guide to

Visualizing Matrix Multiplication as a Linear Combination

· Big Data Zone
Free Resource

Need to build an application around your data? Learn more about dataflow programming for rapid development and greater creativity. 

When multiplying two matrices, there's a manual procedure we all know how to go through. Each result cell is computed separately as the dot-product of a row in the first matrix with a column in the second matrix. While it's the easiest way to compute the result manually, it may obscure a very interesting property of the operation: multiplying A by B is the linear combination of A's columns using coefficients from B. Another way to look at it is that it's a linear combination of the rows of B using coefficients from A.

In this quick post I want to show a colorful visualization that will make this easier to grasp.

Right-Multiplication: Combination of Columns

Let's begin by looking at the right-multiplication of matrix X by a column vector:


Representing the columns of X by colorful boxes will help visualize this:

Matrix by vector

Sticking the white box with a in it to a vector just means: multiply this vector by the scalar a. The result is another column vector - a linear combination of X's columns, with a, b, c as the coefficients.

Right-multiplying X by a matrix is more of the same. Each resulting column is a different linear combination of X's columns:


Matrix by matrix

If you look hard at the equation above and squint a bit, you can recognize this column-combination property by examining each column of the result matrix.

Left-Multiplication: Combination of Rows

Now let's examine left-multiplication. Left-multiplying a matrix X by a row vector is a linear combination of X's rows:


Is represented graphically thus:

Vector by matrix

And left-multiplying by a matrix is the same thing repeated for every result row: it becomes the linear combination of the rows of X, with the coefficients taken from the rows of the matrix on the left. Here's the equation form:

And the graphical form:

Matrix by matrix from the left

Check out the Exaptive data application Studio. Technology agnostic. No glue code. Use what you know and rely on the community for what you don't. Try the community version.

bigdata ,big data ,linear combination ,computer science

Published at DZone with permission of Eli Bendersky, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}