《Python数据分析技术栈》第05章 06 矩阵(Matrices)

06 矩阵(Matrices)

《Python数据分析技术栈》第05章 06 矩阵(Matrices)

A matrix is a two-dimensional data structure, while an array can consist of any number of dimensions.

矩阵是一种二维数据结构,而数组可以包含任意维数。

With the np.matrix class, we can create a matrix object, using the following syntax:

通过 np.matrix 类,我们可以使用以下语法创建一个矩阵对象:

python 复制代码
x=np.matrix([[2,3],[33,3],[4,1]])
#OR
x=np.matrix('2,3;33,3;4,1') #Using semicolons to separate the rows x

Most of the functions that can be applied to arrays can be used on matrices as well. Matrices use some arithmetic operators that make matrix operations more intuitive. For instance, we can use the * operator to get the dot product of two matrices that replicates the functionality of the np.dot function.

大多数可用于数组的函数也可用于矩阵。矩阵使用一些算术运算符,使矩阵运算更加直观。例如,我们可以使用 * 运算符获取两个矩阵的点积,这与 np.dot 函数的功能相同。

Since matrices are just one specific case of arrays and might be deprecated in future releases of NumPy, it is generally preferable to use NumPy arrays.

由于矩阵只是数组的一种特殊情况,而且在未来的 NumPy 版本中可能会被弃用,因此通常最好使用 NumPy 数组。

相关推荐
TF男孩2 小时前
ARQ:一款低成本的消息队列,实现每秒万级吞吐
后端·python·消息队列
该用户已不存在7 小时前
Mojo vs Python vs Rust: 2025年搞AI,该学哪个?
后端·python·rust
站大爷IP9 小时前
Java调用Python的5种实用方案:从简单到进阶的全场景解析
python
用户83562907805114 小时前
从手动编辑到代码生成:Python 助你高效创建 Word 文档
后端·python
c8i14 小时前
python中类的基本结构、特殊属性于MRO理解
python
liwulin050615 小时前
【ESP32-CAM】HELLO WORLD
python
Doris_202315 小时前
Python条件判断语句 if、elif 、else
前端·后端·python
Doris_202315 小时前
Python 模式匹配match case
前端·后端·python
这里有鱼汤15 小时前
Python量化实盘踩坑指南:分钟K线没处理好,小心直接亏钱!
后端·python·程序员
大模型真好玩16 小时前
深入浅出LangGraph AI Agent智能体开发教程(五)—LangGraph 数据分析助手智能体项目实战
人工智能·python·mcp