## Słownik

Wybierz jedno ze słów kluczowych po lewej stronie…

# Linear AlgebraTransposes

Czas czytania: ~25 min

The dot product gives us a compact way to express the formula for an entry of a matrix product: to obtain the $(i,j)$th entry of a matrix product , we dot the $i$th row of and the $j$th column of .

However, the matrix product by itself is not quite flexible enough to handle a common use case: suppose we have two matrices and which contain tabular data stored in the same format. For example, suppose that the columns of store the vectorized word counts for a series of emails sent from Alice, while stores vectorized word counts for a series of emails sent from Bob. If we want to calculate the similarity of each of Alice's email to each of Bob's emails, then we want to dot the columns of —not its rows—with the columns of .

So we define the transpose of a matrix to be the matrix which results from switching the rows and columns of .

Definition
If is an matrix, then its transpose is defined to be the matrix with rows whose th row is equal to the th column of , for each from 1 to .

Example
If then

With this definition in hand, we can write the matrix whose entries are the dot products of columns of and as .

## Transpose properties

Let's develop a few properties of the transpose so that we can manipulate matrix expressions involving the transpose. First, we note that the transpose is a linear operator, meaning that whenever is a constant and and are matrices.

Taking the transpose also interacts nicely with matrix multiplication:

Exercise
Suppose that is an matrix and that is an matrix. Exactly one of the following expressions is equal to in general—identify the correct answer choice by checking the dimensions of each matrix in each expression.

Confirm your conjecture numerically in Python with some random matrices. You can generate a random matrix using np.random.random_sample((m,n)), the transpose of A is accessed as A.T, and the product of A and B is A * B.

Confirm your conjecture numerically in Julia with some random matrices. You can generate a random matrix using rand(m, n).

import numpy as np

Solution. Since is an matrix, the matrix is .

• : this is an matrix multiplied by a matrix, and if it is not defined. If it is defined, it gives an matrix.
• : this is a matrix multiplied by an matrix and hence is a matrix.
• is an matrix, and is an matrix. If this is not defined. If it is defined, it gives an matrix.

We see that the only matrix product that is always defined, and in fact gives the right dimensions, is the second option. And in fact, we have

in general.

The following block of code checks the equation for a particular random example.

import numpy as np
A = np.random.random_sample((3,7))
B = np.random.random_sample((7,3))
np.allclose((A @ B).T, B.T @ A.T)
A = rand(3, 7)
B = rand(7, 3)
isapprox((A * B)', B' * A')

## Symmetric Matrices

In some applications, a matrix will have the property that its $(i,j)(j,i)$th entry. For example, suppose we have an ordered list of 100 cell phone towers, and we define the matrix whose $(i,j)$th entry is equal to the distance from tower to tower . Such a matrix is said to be symmetric.

Definition
If is an matrix satisfying the equation , we say that is symmetric.

Exercise
Suppose that is a symmetric matrix, is a matrix, and . Which of the following is necessarily equal to ?

XEQUATIONX28XEQUATIONX
XEQUATIONX29XEQUATIONX
XEQUATIONX30XEQUATIONX
XEQUATIONX31XEQUATIONX
XEQUATIONX32XEQUATIONX

Solution. We have

Here we used that for any matrix , and that for a symmetric matrix . This leaves (3) as the correct answer. (5) is close, but incorrect if .

In the case where is a matrix and is an for some , then is a matrix, which we may think of as just a number. This means that if and are vectors in then the dot product may be written as . This representation can be useful for manipulating expressions involving dot products:

Exercise
Show that

for all matrices and all vectors and .

Solution. Since we have

In other words, we may move a matrix which is pre-multiplying one of the vectors in a dot product to the other vector, at the cost of taking its transpose. Let's look at one application of this property whose importance will be explored in subsequent sections.

Exercise
Show that for all matrices and all .

Solution. We have

Bruno