矩阵-向量乘法的行与列的解释(Row and Column Interpretations):中英双语

本文是学习这本书的笔记

在这里插入图片描述
网站是:https://web.stanford.edu/~boyd/vmls/

矩阵-向量乘法的行与列的解释

矩阵-向量乘法(Matrix-Vector Multiplication)是线性代数中的基本操作,也是机器学习、数据科学和工程中常用的数学工具。本文将详细解释矩阵-向量乘法中的“行与列”的两种视角,并通过实际例子帮助理解其背后的数学意义。


1. 什么是矩阵-向量乘法?

矩阵 ( A A A) 和向量 ( x x x) 的乘积可以用下面的公式表示:
y = A x y = Ax y=Ax
其中:

  • 矩阵 ( A ∈ R m × n A \in \mathbb{R}^{m \times n} ARm×n) 是一个 ( m × n m \times n m×n) 的矩阵;
  • 向量 ( x ∈ R n x \in \mathbb{R}^n xRn) 是一个 ( n n n)-维列向量;
  • 结果 ( y ∈ R m y \in \mathbb{R}^m yRm) 是一个 ( m m m)-维列向量。

矩阵-向量乘法可以从“”和“”的两种视角来理解。接下来我们分别介绍这两种解释。


2. 从行的角度解释

矩阵-向量乘法可以视为“将向量 ( x x x) 与矩阵的每一行进行内积计算”,具体来说:

矩阵 ( A A A) 的第 ( i i i) 行记为 ( b i T b_i^T biT):
A = [ b 1 T b 2 T ⋮ b m T ] , A = \begin{bmatrix} b_1^T \\ b_2^T \\ \vdots \\ b_m^T \end{bmatrix}, A= b1Tb2TbmT ,
其中每个 ( b i T ∈ R n b_i^T \in \mathbb{R}^n biTRn) 是 ( A A A) 的一行(转置表示为行向量)。

对于 ( y = A x y = Ax y=Ax),结果向量 ( y y y) 的第 ( i i i) 个元素 ( y i y_i yi) 是矩阵第 ( i i i) 行与向量 ( x x x) 的内积:
y i = b i T x , i = 1 , 2 , … , m . y_i = b_i^T x, \quad i = 1, 2, \dots, m. yi=biTx,i=1,2,,m.

公式解读

  • ( b i T x b_i^T x biTx) 表示矩阵第 ( i i i) 行与向量 ( x x x) 的内积;
  • 每一行的内积结果形成 ( y y y) 中的一个元素。

例子:

假设:
A = [ 1 2 3 4 5 6 7 8 9 ] , x = [ 1 2 3 ] . A = \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{bmatrix}, \quad x = \begin{bmatrix} 1 \\ 2 \\ 3 \end{bmatrix}. A= 147258369 ,x= 123 .

计算 ( y = A x y = Ax y=Ax) 时,从行的视角来看:

  1. 取第 1 行 ( b 1 T = [ 1 , 2 , 3 ] b_1^T = [1, 2, 3] b1T=[1,2,3]),计算内积 ( y 1 = b 1 T x = 1 ⋅ 1 + 2 ⋅ 2 + 3 ⋅ 3 = 14 y_1 = b_1^T x = 1 \cdot 1 + 2 \cdot 2 + 3 \cdot 3 = 14 y1=b1Tx=11+22+33=14);
  2. 取第 2 行 ( b 2 T = [ 4 , 5 , 6 ] b_2^T = [4, 5, 6] b2T=[4,5,6]),计算内积 ( y 2 = b 2 T x = 4 ⋅ 1 + 5 ⋅ 2 + 6 ⋅ 3 = 32 y_2 = b_2^T x = 4 \cdot 1 + 5 \cdot 2 + 6 \cdot 3 = 32 y2=b2Tx=41+52+63=32);
  3. 取第 3 行 ( b 3 T = [ 7 , 8 , 9 ] b_3^T = [7, 8, 9] b3T=[7,8,9]),计算内积 ( y 3 = b 3 T x = 7 ⋅ 1 + 8 ⋅ 2 + 9 ⋅ 3 = 50 y_3 = b_3^T x = 7 \cdot 1 + 8 \cdot 2 + 9 \cdot 3 = 50 y3=b3Tx=71+82+93=50)。

最终结果:
y = [ 14 32 50 ] . y = \begin{bmatrix} 14 \\ 32 \\ 50 \end{bmatrix}. y= 143250 .


3. 从列的角度解释

矩阵-向量乘法也可以视为“将矩阵 ( A A A) 的列按照向量 ( x x x) 中的元素加权,并进行线性组合”。具体来说:

矩阵 ( A A A) 的第 ( k k k) 列记为 ( a k a_k ak):
A = [ a 1 , a 2 , … , a n ] , A = [a_1, a_2, \dots, a_n], A=[a1,a2,,an],
其中每个 ( a k ∈ R m a_k \in \mathbb{R}^m akRm) 是 ( A A A) 的一列。

矩阵-向量乘法 ( y = A x y = Ax y=Ax) 可以写成:
y = x 1 a 1 + x 2 a 2 + ⋯ + x n a n , y = x_1 a_1 + x_2 a_2 + \dots + x_n a_n, y=x1a1+x2a2++xnan,
即,结果向量 ( y y y) 是矩阵列向量的线性组合,组合系数由 ( x x x) 的元素给出。

公式解读

  • ( x k a k x_k a_k xkak) 表示用 ( x x x) 中的第 ( k k k) 个元素 ( x k x_k xk) 对矩阵的第 ( k k k) 列进行加权;
  • 把加权后的所有列向量相加,得到结果向量 ( y y y)。

例子:

继续使用相同的矩阵和向量:
A = [ 1 2 3 4 5 6 7 8 9 ] , x = [ 1 2 3 ] . A = \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{bmatrix}, \quad x = \begin{bmatrix} 1 \\ 2 \\ 3 \end{bmatrix}. A= 147258369 ,x= 123 .

从列的视角来看:

  1. ( A A A) 的第 1 列是 ( a 1 = [ 1 , 4 , 7 ] T a_1 = [1, 4, 7]^T a1=[1,4,7]T),加权系数是 ( x 1 = 1 x_1 = 1 x1=1),所以贡献向量为 ( 1 ⋅ a 1 = [ 1 , 4 , 7 ] T 1 \cdot a_1 = [1, 4, 7]^T 1a1=[1,4,7]T);
  2. ( A A A) 的第 2 列是 ( a 2 = [ 2 , 5 , 8 ] T a_2 = [2, 5, 8]^T a2=[2,5,8]T),加权系数是 ( x 2 = 2 x_2 = 2 x2=2),所以贡献向量为 ( 2 ⋅ a 2 = [ 4 , 10 , 16 ] T 2 \cdot a_2 = [4, 10, 16]^T 2a2=[4,10,16]T);
  3. ( A A A) 的第 3 列是 ( a 3 = [ 3 , 6 , 9 ] T a_3 = [3, 6, 9]^T a3=[3,6,9]T),加权系数是 ( x 3 = 3 x_3 = 3 x3=3),所以贡献向量为 ( 3 ⋅ a 3 = [ 9 , 18 , 27 ] T 3 \cdot a_3 = [9, 18, 27]^T 3a3=[9,18,27]T)。

最终结果是所有列向量的线性组合:

y = 1 ⋅ a 1 + 2 ⋅ a 2 + 3 ⋅ a 3 = [ 1 + 4 + 9 4 + 10 + 18 7 + 16 + 27 ] = [ 14 32 50 ] . y = 1 \cdot a_1 + 2 \cdot a_2 + 3 \cdot a_3 = \begin{bmatrix} 1 + 4 + 9 \\ 4 + 10 + 18 \\ 7 + 16 + 27\end{bmatrix}= \begin{bmatrix} 14 \\ 32 \\ 50 \end{bmatrix}. y=1a1+2a2+3a3= 1+4+94+10+187+16+27 = 143250 .


4. 行与列视角的联系与选择
  1. 行视角:更适合理解矩阵-向量乘法的每个输出分量 ( y i y_i yi) 是如何计算的,即通过行与向量的内积。
  2. 列视角:更适合理解结果向量 ( y y y) 是由矩阵列向量的线性组合得到的。

在实际应用中,可以根据问题背景选择合适的视角:

  • 行视角通常用于计算或实现算法;
  • 列视角常用于分析结果或解释几何意义。

5. 结论

矩阵-向量乘法是线性代数中极为重要的操作,而从行和列的两个视角理解,可以帮助我们更深刻地掌握其计算过程与实际意义。无论是从行的内积出发,还是从列的线性组合出发,这两种视角都揭示了矩阵操作在数学和应用中的多样性。

英文版

Matrix-Vector Multiplication: Row and Column Interpretations

Matrix-vector multiplication is a fundamental operation in linear algebra and is widely used in fields like machine learning, data science, and engineering. This article explains the row and column perspectives of matrix-vector multiplication in detail, with practical examples to help clarify the underlying mathematics.


1. What is Matrix-Vector Multiplication?

The product of a matrix (A) and a vector (x) is written as:
y = A x y = Ax y=Ax
where:

  • ( A ∈ R m × n A \in \mathbb{R}^{m \times n} ARm×n) is an ( m × n m \times n m×n) matrix;
  • ( x ∈ R n x \in \mathbb{R}^n xRn) is an ( n n n)-dimensional column vector;
  • ( y ∈ R m y \in \mathbb{R}^m yRm) is the resulting ( m m m)-dimensional column vector.

Matrix-vector multiplication can be understood from two perspectives:

  1. The row view: Treat the result as the dot products of ( x x x) with each row of ( A A A).
  2. The column view: Treat the result as a linear combination of the columns of ( A A A).

2. Row Perspective

In the row perspective, matrix-vector multiplication involves taking the dot product of the vector ( x x x) with each row of the matrix ( A A A). Let ( b i T b_i^T biT) represent the ( i i i)-th row of ( A A A), so:
A = [ b 1 T b 2 T ⋮ b m T ] , A = \begin{bmatrix} b_1^T \\ b_2^T \\ \vdots \\ b_m^T \end{bmatrix}, A= b1Tb2TbmT ,
where each ( b i T ∈ R n b_i^T \in \mathbb{R}^n biTRn) is a row vector.

The ( i i i)-th entry of the result vector ( y y y) is:
y i = b i T x , i = 1 , 2 , … , m . y_i = b_i^T x, \quad i = 1, 2, \dots, m. yi=biTx,i=1,2,,m.

This means:

  • Each entry ( y i y_i yi) is the dot product of ( x x x) with the ( i i i)-th row of ( A A A).
  • The result vector ( y y y) consists of ( m m m) such dot products, one for each row.

Example (Row Perspective)

Suppose:
A = [ 1 2 3 4 5 6 7 8 9 ] , x = [ 1 2 3 ] . A = \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{bmatrix}, \quad x = \begin{bmatrix} 1 \\ 2 \\ 3 \end{bmatrix}. A= 147258369 ,x= 123 .

To compute ( y = A x y = Ax y=Ax):

  1. Take the first row ( b 1 T = [ 1 , 2 , 3 ] b_1^T = [1, 2, 3] b1T=[1,2,3]), and compute the dot product with ( x x x):
    y 1 = 1 ⋅ 1 + 2 ⋅ 2 + 3 ⋅ 3 = 14. y_1 = 1 \cdot 1 + 2 \cdot 2 + 3 \cdot 3 = 14. y1=11+22+33=14.
  2. Take the second row ( b 2 T = [ 4 , 5 , 6 ] b_2^T = [4, 5, 6] b2T=[4,5,6]), and compute the dot product:
    y 2 = 4 ⋅ 1 + 5 ⋅ 2 + 6 ⋅ 3 = 32. y_2 = 4 \cdot 1 + 5 \cdot 2 + 6 \cdot 3 = 32. y2=41+52+63=32.
  3. Take the third row ( b 3 T = [ 7 , 8 , 9 ] b_3^T = [7, 8, 9] b3T=[7,8,9]), and compute the dot product:
    y 3 = 7 ⋅ 1 + 8 ⋅ 2 + 9 ⋅ 3 = 50. y_3 = 7 \cdot 1 + 8 \cdot 2 + 9 \cdot 3 = 50. y3=71+82+93=50.

Thus:
y = [ 14 32 50 ] . y = \begin{bmatrix} 14 \\ 32 \\ 50 \end{bmatrix}. y= 143250 .


3. Column Perspective

In the column perspective, matrix-vector multiplication can be interpreted as a linear combination of the columns of ( A A A), with the elements of ( x x x) serving as the coefficients of the combination. Let ( a k a_k ak) represent the ( k k k)-th column of ( A A A), so:
A = [ a 1 , a 2 , … , a n ] , A = [a_1, a_2, \dots, a_n], A=[a1,a2,,an],
where each ( a k ∈ R m a_k \in \mathbb{R}^m akRm) is a column vector.

The matrix-vector product ( y = A x y = Ax y=Ax) can be written as:
y = x 1 a 1 + x 2 a 2 + ⋯ + x n a n . y = x_1 a_1 + x_2 a_2 + \cdots + x_n a_n. y=x1a1+x2a2++xnan.

This means:

  • ( x k a k x_k a_k xkak) scales the ( k k k)-th column ( a k a_k ak) of ( A A A) by the ( k k k)-th entry ( x k x_k xk) of the vector ( x x x).
  • The result ( y y y) is the sum of these scaled columns.

Example (Column Perspective)

Using the same matrix and vector:
A = [ 1 2 3 4 5 6 7 8 9 ] , x = [ 1 2 3 ] . A = \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{bmatrix}, \quad x = \begin{bmatrix} 1 \\ 2 \\ 3 \end{bmatrix}. A= 147258369 ,x= 123 .

From the column perspective:

  1. The first column of ( A A A) is ( a 1 = [ 1 , 4 , 7 ] T a_1 = [1, 4, 7]^T a1=[1,4,7]T), scaled by ( x 1 = 1 x_1 = 1 x1=1):
    1 ⋅ a 1 = [ 1 , 4 , 7 ] T . 1 \cdot a_1 = [1, 4, 7]^T. 1a1=[1,4,7]T.
  2. The second column of ( A A A) is ( a 2 = [ 2 , 5 , 8 ] T a_2 = [2, 5, 8]^T a2=[2,5,8]T), scaled by ( x 2 = 2 x_2 = 2 x2=2):
    2 ⋅ a 2 = [ 4 , 10 , 16 ] T . 2 \cdot a_2 = [4, 10, 16]^T. 2a2=[4,10,16]T.
  3. The third column of ( A A A) is ( a 3 = [ 3 , 6 , 9 ] T a_3 = [3, 6, 9]^T a3=[3,6,9]T), scaled by ( x 3 = 3 x_3 = 3 x3=3):
    3 ⋅ a 3 = [ 9 , 18 , 27 ] T . 3 \cdot a_3 = [9, 18, 27]^T. 3a3=[9,18,27]T.

Add the scaled columns:
y = 1 ⋅ a 1 + 2 ⋅ a 2 + 3 ⋅ a 3 = [ 1 + 4 + 9 4 + 10 + 18 7 + 16 + 27 ] = [ 14 32 50 ] . y = 1 \cdot a_1 + 2 \cdot a_2 + 3 \cdot a_3 = \begin{bmatrix} 1 + 4 + 9 \\ 4 + 10 + 18 \\ 7 + 16 + 27 \end{bmatrix}= \begin{bmatrix} 14 \\ 32 \\ 50 \end{bmatrix}. y=1a1+2a2+3a3= 1+4+94+10+187+16+27 = 143250 .


4. Connection Between the Two Perspectives
  • Row Perspective: Computes the entries of the result vector ( y y y) one at a time, using dot products between the rows of ( A A A) and the vector ( x x x). This perspective is often used in implementation and numerical computation.
  • Column Perspective: Views the result vector ( y y y) as a linear combination of the columns of ( A A A), scaled by the entries of ( x x x). This perspective is useful for understanding geometric interpretations and applications like data transformations.

The two perspectives are mathematically equivalent and simply offer different ways to interpret the same operation.


5. Practical Applications
  1. Row Perspective in Machine Learning:

    • Useful when processing datasets where rows represent individual samples and columns represent features.
    • Example: In a neural network, ( A A A) can represent weights, and ( x x x) the input features. The output ( y y y) represents weighted sums for each neuron.
  2. Column Perspective in Data Transformation:

    • Common in computer graphics and signal processing, where each column represents a basis vector, and the result is a transformation of ( x x x) into a new coordinate system.
    • Example: Principal Component Analysis (PCA) involves projecting data onto principal components (columns).

6. Conclusion

Matrix-vector multiplication is a versatile operation that can be understood from two complementary perspectives:

  • The row perspective, which emphasizes the dot product computation for each entry of the result vector.
  • The column perspective, which highlights the linear combination of matrix columns.

By understanding both views, you can better analyze and apply this operation in various fields like machine learning, data analysis, and linear systems.

后记

2024年12月20日13点01分于上海,在GPT4o的辅助下完成。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/890219.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【Vulkan入门】18-Texture[2/4]

文章目录 TextureTexture::LoadImage() 本篇不叨叨了,接着 上篇。 本篇介绍如何创建纹理图片。 Texture 这个类的作用是传入一个图片的路径,构建纹理图片和Sampler。 Texture::LoadImage() 这个方法是创建纹理Image 代码比较长,我先把代码…

MFC 应用程序语言切换

在开发多语言支持的 MFC 应用程序时,如何实现动态语言切换是一个常见的问题。在本文中,我们将介绍两种实现语言切换的方式,并讨论其优缺点。同时,我们还会介绍如何通过保存配置文件来记住用户的语言选择,以及如何在程序…

torch.multiprocessing 向Process传递对象参数报错 Can‘t pickle local object

如下代码所示,使用torch.multiprocessing启动多进程,并传递了model和image_processor两个对象作为参数。 from torch.multiprocessing import Process, Queue, Manager...p3 Process(targetframe_memory_manager,args(model, image_processor, frame_q…

基于海思soc的智能产品开发(巧用mcu芯片)

【 声明:版权所有,欢迎转载,请勿用于商业用途。 联系信箱:feixiaoxing 163.com】 对于开发车规级嵌入式软件的同学来说,socmcu这样的组合,他们并不陌生。但是传统的工业领域,比如发动机、医疗或…

带有 Elasticsearch 和 Langchain 的 Agentic RAG

作者:来自 Elastic Han Xiang Choong 讨论并实现 Elastic RAG 的代理流程,其中 LLM 选择调用 Elastic KB。 更多阅读:Elasticsearch:基于 Langchain 的 Elasticsearch Agent 对文档的搜索。 简介 代理是将 LLM 应用于实际用例的…

SmartX分享:NVMe-oF 介绍、SMTX ZBS 如何选择高性能场景解决方案与如何实现

目录 背景什么是 NVMe-oFZBS AccessiSCSI 与 iSERNMVe-oF 介绍NVMeNVMe-oFNVMe-oF 承载网络(数据平面) ZBS NVMe-oF 实现ZBS 接入策略ZBS 接入点分配策略性能测试 为什么要支持 RoCE引用 背景 前几篇文章,我们认识到了 SmartX 公司产品 SMTX…

单片机flash rom ram 理解

您说得对,传统意义上的 ROM(Read-Only Memory, 只读存储器) 是一种非易失性存储器,掉电后不会丢失数据。但在很多单片机(例如STM8)中,所谓的 EEPROM 或 Flash 也常被称作“ROM”来存…

全面解析 Golang Gin 框架

1. 引言 在现代 Web 开发中,随着需求日益增加,开发者需要选择合适的工具来高效地构建应用程序。对于 Go 语言(Golang)开发者来说,Gin 是一个备受青睐的 Web 框架。它轻量、性能高、易于使用,并且具备丰富的…

【机器学习】机器学习的基本分类-强化学习(Reinforcement Learning, RL)

强化学习(Reinforcement Learning, RL)是一种基于试错的方法,旨在通过智能体与环境的交互,学习能够最大化累积奖励的策略。以下是强化学习的详细介绍。 强化学习的核心概念 智能体(Agent) 执行动作并与环境…

MyBatis-Plus中isNull与SQL语法详解:处理空值的正确姿势

目录 前言1. 探讨2. 基本知识3. 总结 前言 🤟 找工作,来万码优才:👉 #小程序://万码优才/r6rqmzDaXpYkJZF 基本的Java知识推荐阅读: java框架 零基础从入门到精通的学习路线 附开源项目面经等(超全&#x…

Spring Boot 项目创建

创建一个新项目: 打开 Spring Initializr 网址:https://start.spring.io/ ,然后创建一个新项目: springboot3.3.5_jdk17: Project(Maven)编程语言(Java 17)Spring Boo…

基于蓝牙通信的手机遥控智能灯(论文+源码)

1.系统设计 灯具作为人们日常生活的照明工具为人们生活提供光亮,本次基于蓝牙通信的手机遥控智能灯设计功能如下: (1)用户可以通过蓝牙通信模块的作用下,在手机端遥控切换智能灯不同的工作模式; &#x…

【VUE】13、安装nrm管理多个npm源

nrm(npm registry manager)是一个 npm 源管理器,它允许用户快速地在不同的 npm 源之间进行切换,以提高包管理的速度和效率。以下是对 nrm 使用的详细介绍: 1、安装nrm 在使用 nrm 之前,需要先确保已经安装…

ASR-LLM-TTS 实时语音对话助手:语音识别、大模型对话、声音生成

参考:https://blog.csdn.net/weixin_42357472/article/details/137020794 asr:funasr-SenseVoiceSmall 离线 llm:deepseek 在线api tts:edge-tts 在线api import pyaudio import wave import threading import numpy as np import time from queue import Queue import web…

为什么光耦固态继电器(SSR)值得关注?

光耦固态继电器(SSR)作为现代电子控制系统中不可或缺的关键组件,正逐步取代传统机械继电器。通过利用光耦合技术,SSR不仅能够提供更高的可靠性,还能适应更加复杂和严苛的应用环境。在本文中,我们将深入探讨…

AI @国际象棋世界冠军赛: 从棋盘到科研创新之路

点击屏末 | 阅读原文 | 在小红书和 Google 谷歌回顾 WCC

矩阵运算的复杂度分析(Complexity Analysis of Matrix Operations):中英双语

矩阵运算的复杂度分析 矩阵运算在科学计算、机器学习、图像处理等领域中起着至关重要的作用。了解各种常见矩阵运算的复杂度,对于优化算法、提高计算效率具有重要意义。在这篇博客中,我们将详细探讨矩阵加法、标量乘法、矩阵转置、矩阵-向量乘法等基本矩…

leetcode二叉搜索树部分笔记

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 二叉搜索树 1. 二叉搜索树的最小绝对差2. 二叉搜索树中第 K 小的元素3. 验证二叉搜索树 1. 二叉搜索树的最小绝对差 给你一个二叉搜索树的根节点 root ,返回 树中…

如何创建属于自己的大语言模型:从零开始的指南

如何创建属于自己的大语言模型:从零开始的指南 为什么要创建自己的大语言模型? 随着人工智能的快速发展,大语言模型(LLM)在各种场景中表现出了卓越的能力,例如文本生成、对话交互和内容总结等。虽然市场上…

计算机工作流程

分析下面的计算机工作流程: 1.取数a至ACC:PC程序寄存器自增1,变成0(可以理解为PC初始从-1开始自增);接着PC把当前指令的地址给到MAR(地址寄存器);MAR拿到当前地址后&…